Polygon

當 fillOrder 在 0x 協議上時,交易受到尊重

  • December 13, 2021

我正在嘗試編寫一個使用 0x 協議智能合約銷售 NFT 的應用程序,並在 Mumbai Polygon 測試網上對其進行測試,部署了我的測試 ER721 合約和測試 ERC20 合約。從https://gist.github.com/rahuldamodar94/6bdd022f3457934f2a104fd5f4bb45e4獲得 0x 合約地址。但是,當呼叫 fillOrder Exchange 方法時,我收到錯誤“交易已被 EVM 還原”

exchangeAddr = '0x533dc89624dcc012c7323b41f286bd2df478800b';    // taken from gistfile.txt
devUtilAddr = '0x7a2d89c4cb4b28b9cef9f269d48b3aecf0f549b7'
const erc20ProxyAddr = "0x0b47076aaa5246411458fcf85494f41bbfdb8470";
const erc721ProxyAddr = "0xff7ca10af37178bdd056628ef42fd7f799fac77c";

const currentTime = Date.now();
const expiry = Math.ceil(currentTime/1000) + 36 * 3600

let order = {
       makerAddress: process.env.MAKER_ADDRESS,        // seller
       takerAddress: process.env.TAKER_ADDRESS,        // buyer
       senderAddress: process.env.TAKER_ADDRESS,
       feeRecipientAddress: '0x0000000000000000000000000000000000000000',
       makerAssetAmount: tokenId,
       takerAssetAmount: amount,
       makerFee: '0',
       takerFee: '0',
       expirationTimeSeconds: expiry,                                    
       salt: '125',
       makerAssetData: '0x', 
       takerAssetData: '0x', 
       makerFeeAssetData: '0x',
       takerFeeAssetData: '0x',
       chainId: chainId,
       exchangeAddress: exchangeAddr,
   };

if (!initialized)
       await this.init();

const exchange = new web3Taker.eth.Contract(artifacts.Exchange.compilerOutput.abi, exchangeAddr);
const devUtils = new web3Taker.eth.Contract(artifacts.DevUtils.compilerOutput.abi, devUtilAddr);

const erc721Addr = '0xBa461089AC314b56EB51920F23971FE4adF8A113';
const erc71Instance = new web3Maker.eth.Contract(erc721.abi, erc721Addr);

const erc20addr = '0x4732b9252984c255BB841CeDb3F3aE673048Da2d';     // PolyTest20 token

const makerAssetData = await devUtils.methods.encodeERC721AssetData(polyNFTAddr, BigNumber(1)).call();
const takerAssetData = await devUtils.methods.encodeERC20AssetData(erc20addr).call();
order.makerAssetData = makerAssetData;
order.takerAssetData = takerAssetData;

const sOrder = await OrderUtils.signatureUtils.ecSignOrderAsync(localKeyProviderMaker, order, process.env.MAKER_ADDRESS);

let isValid = await exchange.methods.isValidOrderSignature(order, sOrder.signature).call();
if (!isValid)
       return;

const erc20Instance = new web3Taker.eth.Contract(erc21Test20.abi, erc20addr);

let isApproved1 = await erc20Instance.methods.approve(erc20ProxyAddr, amount).send({from: takerAccount});
if (!isApproved1) 
         return;

let isApproved2 = await erc721Instance.methods.approve(erc721ProxyAddr, tokenId).send({from: makerAcount });
if (!isApproved2)
         return;

let res = await exchange.methods.fillOrder(order, new BigNumber(100000), sOrder.signature)
                .send({from: takerAccount, value:10000000, gas:18000000});

有人能說出這段程式碼有什麼問題或指出工作範例嗎?謝謝

終於可以成功執行 fillOrder 了。實際上,初始程式碼幾乎是正確的,幾乎沒有錯誤 - 令牌編號應該在 encodeERC721AssetData 呼叫中,令牌數量 (1) - 是 makerAssetAmount 欄位的值。並且還增加了 fillOrder 呼叫中的值。這是程式碼範例: const erc721ProxyAddr = deployments

$$ chainId $$.erc721代理;const erc20ProxyAddr = 部署$$ chainId $$.erc20代理;

   const exchangeAddr = deployments[chainId].exchange;
   const exchange = new web3Taker.eth.Contract(artifacts.Exchange.compilerOutput.abi, exchangeAddr);
   
   const polyNFTAddr = deployments[chainId].polyNFT;
   const polyNFTinstance = new web3Maker.eth.Contract(PolyNFT.abi, polyNFTAddr);       

   const polyTest20Addr = deployments[chainId].polyTest20;
   const polyTest20Instance = new web3Taker.eth.Contract(PolyTest20.abi, polyTest20Addr);

   const makerAssetData = OrderUtils.assetDataUtils.encodeERC721AssetData(polyNFTAddr, BigNumber(tokenId));
   const takerAssetData = OrderUtils.assetDataUtils.encodeERC20AssetData(polyTest20Addr);

   const order = {
       makerAddress: process.env.MAKER_ADDRESS,        // seller
       takerAddress: process.env.TAKER_ADDRESS,        // buyer
       senderAddress: NULL_ADDRESS,
       feeRecipientAddress: NULL_ADDRESS,
       makerAssetAmount: '1',                            // how many tokens to sell
       takerAssetAmount: '100000', //   amount,                       // price
       makerFee: '0',
       takerFee: '0',
       expirationTimeSeconds: '1938807983', // expiry,                                    
       salt: '125',                                      // random number
       makerAssetData: makerAssetData,
       takerAssetData: takerAssetData,       //  await devUtils.encodeERC20AssetData(erc20.address),
       makerFeeAssetData: NULL_BYTES,
       takerFeeAssetData: NULL_BYTES,
     
       chainId: chainId,
      exchangeAddress: exchangeAddr,
   };

  console.log(order);

  const sOrder = await OrderUtils.signatureUtils.ecSignOrderAsync(localKeyProviderMaker, order, process.env.MAKER_ADDRESS);

   let isValid = await exchange.methods.isValidOrderSignature(order, sOrder.signature).call();
   if (!isValid)
       return;

   let isApproved1 = await polyTest20Instance.methods.approve(erc20ProxyAddr, amount).send({from: takerAccount});
   if (!isApproved1) 
           return;
           
   let isApproved2 = await polyNFTinstance.methods.approve(erc721ProxyAddr, tokenId).send({from: makerAccount });
   if (!isApproved2)
         return;

   let res = await exchange.methods.fillOrder(order, amount, sOrder.signature)
                       .send({from: takerAccount, value: '3000000000000000', gas:18000000});

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