Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/update mint nft doc #1653

Merged
merged 8 commits into from
Aug 5, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/build/isc/v1.1/docs/how-tos/core-contracts/nft/mint-nft.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ The Stardust update allows you to create your own NFTs. You can also use [IRC27]

2. Get the senders AgentID:

The `ISCAgentID` represents the identifier of the agent (user or contract) whose NFTs you want to retrieve. You can get the `AgentID` from the sender by calling `ISC.sandbox.getSenderAccount()`.

```solidity
ISCAgentID memory agentID = ISC.sandbox.getSenderAccount();
```

3. Create an `IRC27Metadata` struct with all the needed data:
vivekjain23 marked this conversation as resolved.
Show resolved Hide resolved

:::tip
You can refer to [Get NFT Metadata guide](https://wiki.iota.org/isc/how-tos/core-contracts/nft/get-nft-metadata/) to understand how to create an `IRC27Metadata`
vivekjain23 marked this conversation as resolved.
Show resolved Hide resolved
:::

The`IRC27Metadata` struct in Solidity is designed to hold the metadata for a Non-Fungible Token (NFT) according to the IRC27 standard. This struct includes various fields that describe the NFT, such as its standard, version, MIME type, URI, and name. Here's how to create and use this struct:

```solidity
IRC27NFTMetadata memory metadata = IRC27NFTMetadata({
standard: "IRC27",
Expand All @@ -35,6 +43,7 @@ IRC27NFTMetadata memory metadata = IRC27NFTMetadata({
});
```


4. Create all the data for the core contract call. To do so, you should create a new `ISCDict` with 2 parameters like specified in the reference docs for [`mintNFT`](../../../reference/core-contracts/accounts.md#mintnfti-immutabledata-a-agentid-c-collectionid-w-withdrawonmint)
* `I` is the immutable metadata we fill with the IRC27 metadata and
* `a` is the AgendID of the owner of the NFT
Expand Down Expand Up @@ -88,15 +97,27 @@ pragma solidity ^0.8.0;
import "@iota/iscmagic/ISC.sol";

contract NFTContract {
// Event emitted when a new NFT is minted
event MintedNFT(bytes mintID);

/**
vivekjain23 marked this conversation as resolved.
Show resolved Hide resolved
* @notice Mints a new NFT with the provided metadata and storage deposit
* @param _name The name of the NFT
* @param _mimeType The MIME type of the NFT
* @param _uri The URI where the NFT data is stored
* @param _storageDeposit The amount of storage deposit required
*/
function mintNFT(string memory _name, string memory _mimeType, string memory _uri, uint64 _storageDeposit) public payable {
require(msg.value == _storageDeposit*(10**12), "Please send exact funds to pay for storage deposit");

// Create an ISCAssets object for the allowance with the base tokens
ISCAssets memory allowance;
allowance.baseTokens = _storageDeposit;

// Retrieve the sender's account ID
ISCAgentID memory agentID = ISC.sandbox.getSenderAccount();

// Create the metadata for the NFT
IRC27NFTMetadata memory metadata = IRC27NFTMetadata({
standard: "IRC27",
version: "v1.0",
Expand All @@ -105,31 +126,49 @@ contract NFTContract {
name: _name
});

// Prepare the parameters dictionary for the ISC call
ISCDict memory params = ISCDict(new ISCDictItem[](2));
params.items[0] = ISCDictItem("I", bytes(IRC27NFTMetadataToString(metadata)));
params.items[1] = ISCDictItem("a", agentID.data);

// Call the ISC sandbox to mint the NFT
ISCDict memory ret = ISC.sandbox.call(
ISC.util.hn("accounts"),
ISC.util.hn("mintNFT"),
params,
allowance
);

// Emit the MintedNFT event with the returned mint ID
emit MintedNFT(ret.items[0].value);
}

/**
* @notice Retrieves the NFT ID associated with a given mint ID
* @param mintID The mint ID of the NFT
* @return The NFT ID associated with the provided mint ID
*/
function getNFTIDFromMintID(bytes memory mintID) public view returns (bytes memory) {
// Prepare the parameters dictionary for the ISC call
ISCDict memory params = ISCDict(new ISCDictItem[](1));
params.items[0] = ISCDictItem("D", mintID);

// Call the ISC sandbox to get the NFT ID
ISCDict memory ret = ISC.sandbox.callView(
ISC.util.hn("accounts"),
ISC.util.hn("NFTIDbyMintID"),
params
);

// Return the NFT ID
return ret.items[0].value;
}

/**
* @notice Converts an IRC27NFTMetadata struct to a JSON string
* @param metadata The metadata to convert
* @return The JSON string representation of the metadata
*/
function IRC27NFTMetadataToString(IRC27NFTMetadata memory metadata)
public
pure
Expand Down
Loading