Nft

向憑證添加新參數(惰性鑄幣)

  • April 12, 2022

我正在嘗試使用優惠券來懶惰地鑄造 NFT。我主要使用此 GitHub 儲存庫中的程式碼:https ://github.com/ipfs-shipyard/nft-school-examples/tree/main/lazy-minting 。我決定在(類中)中添加兩個新參數(一個 uint256 參數royaltyAmount和一個地址)。我還描述了智能合約函式中的新參數。添加後,我開始從智能合約的函式中接收錯誤的地址(一個完全任意的地址)。有人能幫我嗎?royaltyReceiver``NFTVoucher``LazyMinter``_hash``_verify

以下是我向createVoucher函式添加新參數的方式:

/**
  * Creates a new NFTVoucher object and signs it using this LazyMinter's signing key.
  *
  * @param {ethers.BigNumber | number} tokenId the id of the un-minted NFT
  * @param {string} uri the metadata URI to associate with this NFT
  * @param {ethers.utils.getAddress | address} royaltyReceiver the address of which the royalty fee will be sent
  * @param {ethers.BigNumber | number} royaltyAmount the percentage of royalty fee
  * @param {ethers.BigNumber | number} minPrice the minimum price (in wei) that the creator will accept to redeem this NFT. defaults to zero
  *
  * @returns {NFTVoucher}
  */
 async createVoucher(tokenId, uri, royaltyReceiver, royaltyAmount, minPrice = 0) {
   const voucher = { tokenId, minPrice, uri, royaltyReceiver, royaltyAmount}
   const domain = await this._signingDomain()
   const types = {
     NFTVoucher: [
       {name: "tokenId", type: "uint256"},
       {name: "minPrice", type: "uint256"},
       {name: "uri", type: "string"},
       {name: "royaltyReceiver", type: "address"},
       {name: "royaltyAmount", type: "uint256"}
     ]
   }

在我的智能合約中,我改變了_hash這樣的:

// @notice Returns a hash of the given NFTVoucher, prepared using EIP712 typed data hashing rules.
 /// @param voucher An NFTVoucher to hash.
 function _hash(NFTVoucher calldata voucher) internal view returns (bytes32) {
   return _hashTypedDataV4(keccak256(abi.encode(
     keccak256("NFTVoucher(uint256 tokenId,uint256 minPrice,string uri, address royaltyReceiver, uint256 royaltyAmount)"),
     voucher.tokenId,
     voucher.minPrice,
     keccak256(bytes(voucher.uri)),
     voucher.royaltyReceiver,
     voucher.royaltyAmount
   )));
 }

我也改變了NFTVoucher這樣的結構:

/// @notice Represents an un-minted NFT, which has not yet been recorded into the blockchain. A signed voucher can be redeemed for a real NFT using the redeem function.
 struct NFTVoucher {
   /// @notice The id of the token to be redeemed. Must be unique - if another token with this ID already exists, the redeem function will revert.
   uint256 tokenId;

   /// @notice The minimum price (in wei) that the NFT creator is willing to accept for the initial sale of this NFT.
   uint256 minPrice;

   /// @notice The metadata URI to associate with this token.
   string uri;

   /// @notice The address of which the royalty fee will be sent.
   address royaltyReceiver;

   /// @notice The percentage of royalty fee
   uint256 royaltyAmount;

   /// @notice the EIP-712 signature of all other fields in the NFTVoucher struct. For a voucher to be valid, it must be signed by an account with the MINTER_ROLE.
   bytes signature;
 }

所以問題是我createVoucher返回的NFTVoucher順序與我在智能合約中定義 NFTVoucher 結構的順序不同。

引用自:https://ethereum.stackexchange.com/questions/124400