Erc-721

0x 協議 ERC721Order - 嘗試執行任何交易以填寫或檢查已簽署訂單的狀態失敗

  • April 19, 2022

我正在嘗試與使用來自**@0x/protocol-utils的****ERC721Order**創建的簽名訂單進行互動。使用以下文件創建和簽署訂單:https ://docs.0x.org/nft-support/guides/signing-orders#signing-with-ethers

訂單範例:

const order = new ERC721Order({
 chainId: 4, // rinkeby
 verifyingContract: '0xdef1c0ded9bec7f1a1670819833240f027b25eff', // https://github.com/0xProject/protocol/blob/development/packages/contract-addresses/addresses.json
 direction: NFTOrder.TradeDirection.SellNFT,
 erc20Token: ETH_TOKEN_ADDRESS, // This address means eth, which we want.
 erc20TokenAmount: new BigNumber(optionMinPriceWei), // token amount in wei (i.e. the buy it now price)
 erc721Token: '0x0', // The actual erc721 contract address   
 erc721TokenId: new BigNumber('17'), // token id
 maker, // address of user selling the erc721 token
 taker: '0x0000000000000000000000000000000000000000', // Who can fill this order. May be NULL (0x000...) to allow anyone.
 nonce: new BigNumber(getRandomInt(10, 5000)), // random number 10-5000. TODO later https://docs.0x.org/nft-support/guides/creating-orders#choosing-a-nonce
 expiry: new BigNumber(Math.floor(Date.now() / 1000 + 86400)), // 1 day from now
 fees: [],
 erc721TokenProperties: [],
});

在客戶端中籤名並將“rawSignature”+訂單數據儲存在我自己的數據庫中。我正在嘗試使用另一個錢包與訂單進行互動,但交易失敗。

我試圖以兩種不同的方式做到這一點,但到目前為止沒有成功:

1)在 GitHub ( https://github.com/0xProject/0x-starter-project/blob/master/src/scenarios/fill_erc20_rfq_order_with_maker_order_signer.ts ) 中使用@0x/contract-wrappers庫,但得到“執行恢復" 來自與合約的不同互動的消息,例如:getERC721OrderStatusvalidateERC721OrderPropertiesbuyERC721(甚至沒有讓 MetaMask 彈出以供以後使用)。

程式碼範例:

 const { signature: rawSignature, erc721TokenID, erc20TokenAmount, expiry, nonce } = sellOrder; // stored in db
 const contractWrappers = new ContractWrappers(provider, { chainId: CHAIN_ID });

 const order = {
   taker: '0x0000000000000000000000000000000000000000', // Tried using the taker address
   direction: NFTOrder.TradeDirection.SellNFT, // Tried changing this
   maker: sellOrder.maker,
   erc20Token: sellOrder.erc20Token,
   erc721Token: sellOrder.erc721Token,
   nonce: new BigNumber(nonce), // Tried using string
   expiry: new BigNumber(expiry), // Tried using string
   erc721TokenId: new BigNumber(erc721TokenID), // Tried using string
   erc20TokenAmount: new BigNumber(erc20TokenAmount), // Tried using string
   fees: sellOrder.fees,
   erc721TokenProperties: [], // ??
 };

 const { v, r, s } = ethers.utils.splitSignature(rawSignature);
 const signature: Signature = {
   signatureType: SignatureType.EIP712,
   v,
   r,
   s,
 };

 const orderStatus = await contractWrappers.exchangeProxy
   .getERC721OrderStatus(order)
   .callAsync()
   .catch((error) => {
     console.error('getERC721OrderStatus', error); // catch to continue
   });
 console.log(orderStatus);

 const isValidOrder = await contractWrappers.exchangeProxy
   .validateERC721OrderProperties(order, new BigNumber(erc721TokenID))
   .callAsync()
   .catch((error) => {
     console.error('validateERC721OrderProperties', error); // catch to continue
   });
 console.log(isValidOrder);

 await contractWrappers.exchangeProxy
   .buyERC721(order, signature, '0x')
   // Also tried estimating gas
   .awaitTransactionSuccessAsync({
     from: taker,
     value: order.erc20TokenAmount,
     // from https://github.com/0xProject/0x-starter-project/blob/master/src/configs.ts
     gasPrice: 20e9,
     gas: 800000,
   });

2)使用 abi ( https://github.com/0xProject/protocol/blob/c1177416f50c2465ee030dacc14ff996eebd4e74/packages/contract-artifacts/artifacts/IZeroEx.json ) 和合約地址(“0xdef1c0ded9bec7f1a16708198eff33240 ) 創建合約實例”) 我正在成功地與 ERC721 等其他契約一起做。對於這一點,buyERC721 方法的執行確實打開了我的 MetaMask 以簽名並發送 tx,但它失敗並顯示以下內容:錯誤:交易失敗$$ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION $$. 視圖函式出現相同的錯誤:getERC721OrderStatusvalidateERC721OrderProperties

範常式式碼:

const { signature: rawSignature, erc721TokenID, erc20TokenAmount, expiry, nonce } = sellOrder;
 const order: any = {
   taker: '0x0000000000000000000000000000000000000000',
   direction: NFTOrder.TradeDirection.SellNFT,
   maker: sellOrder.maker,
   erc20Token: sellOrder.erc20Token,
   erc721Token: sellOrder.erc721Token,
   nonce: String(nonce) as any,
   expiry: String(expiry) as any,
   erc721TokenId: String(erc721TokenID) as any,
   erc20TokenAmount: String(erc20TokenAmount) as any,
   fees: sellOrder.fees,
   erc721TokenProperties: [], // ??
 };
 const { v, r, s } = ethers.utils.splitSignature(rawSignature);
 const signature: Signature = {
   signatureType: SignatureType.EIP712,
   v,
   r,
   s,
 };

 await getERC721OrderStatus(order).catch((error: any) => {
   console.error('getERC721OrderStatus', error);
 });

 await validateERC721OrderProperties(order, order.erc721TokenId).catch((error: any) => {
   console.error('validateERC721OrderProperties', error);
 });

 const overrides: PayableOverrides = {
   value: order.erc20TokenAmount as any,
   gasLimit: '800000',
 };

 // genTransactionFn - returns a wrapper fn that calls the callback (buyERC721) with any args sent
 // and waits for it to have at least 1 confirmation
 // this helper is being used for other contract interactions (not 0x) successfully.
 const buyERC721Fn = genTransactionFn(buyERC721);
 const response = await buyERC721Fn(order, signature, '0x', overrides);

 return response;

0x v4 未部署在 Rinkeby 上;目前唯一部署它的測試網是 Ropsten。您可以在此備忘單中看到部署了 0x v4 的鏈列表。

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