我收集了图片,每张图片都有一些额外的数据(稀有度、ipfs 中的哈希、一些属性等),它们存储在一个 JSON 文件中,我存储在 IPFS 中。我正在尝试制作符合 NEP-171 标准的 NEAR NFT 合约。
我正在浏览“英雄归零”教程并获得了 NFT 合约结构的主要思想,但不明白什么是铸造我的代币集合以进行合约的正确方法。
教程中合约的 mint 函数是:
#[payable]
pub fn nft_mint(&mut self, token_id: TokenId, metadata: TokenMetadata, receiver_id: AccountId) {
//measure the initial storage being used on the contract
let initial_storage_usage = env::storage_usage();
//specify the token struct that contains the owner ID
let token = Token {
//set the owner ID equal to the receiver ID passed into the function
owner_id: receiver_id,
};
//insert the token ID and token struct and make sure that the token doesn't exist
assert!(
self.tokens_by_id.insert(&token_id, &token).is_none(),
"Token already exists"
);
//insert the token ID and metadata
self.token_metadata_by_id.insert(&token_id, &metadata);
//call the internal method for adding the token to the owner
self.internal_add_token_to_owner(&token.owner_id, &token_id);
//calculate the required storage which was the used - initial
let required_storage_in_bytes = env::storage_usage() - initial_storage_usage;
//refund any excess storage if the user attached too much. Panic if they didn't attach enough to cover the required.
refund_deposit(required_storage_in_bytes);
}
据我了解,我应该为我的每个令牌制作 JSON 文件,然后将它们上传到 ipfs(我得到了将近 2600 个令牌,所以文件数将是相同的)。在这些 JSON 中,我应该收集有关令牌的所有信息(png 文件的 URL、统计信息和其他信息)。然后我应该启动我的合约的 mint 函数 2600 次,并将 ipfs 中的 JSON 路径作为 TokenMetaData 参数的一部分。
这是正确的方法吗?如果是这样,我应该如何自动化这个过程?
我想通过编写一些javascript代码来从前端实现它,这些代码将在循环中启动mint函数或类似的东西。或者也许我应该编写另一个将 NFT 向量作为参数的 mint 函数?