0x
正確使用 NFT Swap SDK v4 的過期時間
創建一個 NFT 交易訂單,其中製造商出售單個 721 NFT,並且接受者(與製造商相同的地址)提出以 eth 的價格購買它。無論我將到期值設置為什麼,在估算 gas 時交易都會失敗。只有當到期設置為永不過期的預設值時,我才能讓它工作——
2524604400
這是一個工作範例,最小程度地改編自 nft trader sdk 範例—
export const nftSwapTestExample = async ( provider: BaseProvider, signer: Signer, accountAddress: string, expiresInSeconds: number, ) => { // Scenario: User A wants to sell their CryptoPunk for 420 WETH const chainId = await signer.getChainId(); // Set up the assets we want to swap (CryptoPunk #69 and 420 WETH) const CRYPTOPUNK: SwappableAssetV4 = { tokenAddress: '0xc3415e01ecd8021e1608fda6c7f7a75af0ed5be0', tokenId: '0', type: 'ERC721', // 'ERC721' or 'ERC1155' }; const FOUR_HUNDRED_TWENTY_WETH: SwappableAssetV4 = { tokenAddress: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', // ETH contract address amount: ethers.utils.parseEther('0.0001').toString(), type: 'ERC20', }; // [Part 1: Maker (owner of the Punk) creates trade] const nftSwapSdk = new NftSwapV4(provider, signer, chainId); const walletAddressMaker = accountAddress; // Approve NFT to trade (if required) const needsApproval = await nftSwapSdk.loadApprovalStatus(CRYPTOPUNK, walletAddressMaker); if (!needsApproval.contractApproved && !needsApproval.tokenIdApproved) { await nftSwapSdk.approveTokenOrNftByAsset(CRYPTOPUNK, walletAddressMaker); } const expiry = Math.floor(Date.now() / 1000 + expiresInSeconds); // Build order const order = nftSwapSdk.buildOrder( CRYPTOPUNK, // Maker asset to swap FOUR_HUNDRED_TWENTY_WETH, // Taker asset to swap walletAddressMaker, { expiry }, ); // Sign order so order is now fillable const signedOrder = await nftSwapSdk.signOrder(order); // [Part 2: Taker that wants to buy the punk fills trade] // Fill order :) const fillTx = await nftSwapSdk.fillSignedOrder(signedOrder); const fillTxReceipt = await nftSwapSdk.awaitTransactionHash(fillTx.hash); console.log(`🎉 🥳 Order filled. TxHash: ${fillTxReceipt.transactionHash}`); }; // expires in 1 hour, fails await nftSwapTestExample(provider, signer, 'address', 60*60); // expires in 1 day, fails await nftSwapTestExample(provider, signer, 'address', 60*60*24);
感謝您的報告。我修復了
buildOrder
函式以正確支持傳遞原始 unix 時間戳以進行到期。有機會請更新到 v0.21!現在
expiry
正確地支持對Date
像或 unix 時間戳(作為一種number
類型)。