0

I am trying to write an app that sells NFT using 0x protocol smart contracts and test it on Mumbai Polygon testnet, Deployed my test ER721 contract and test ERC20 contract. Got 0x contract addresses from https://gist.github.com/rahuldamodar94/6bdd022f3457934f2a104fd5f4bb45e4. However I am getting error “Transaction has been reverted by the EVM” when call fillOrder Exchange method

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});

Could someone tell what is wrong in this code or point to the working example? Thank you

1
  • Found few mistakes i this code: 1) makerAssetAmount shoudl be 1 and tokenId is an argument for encodeERC721AssetData, 2) changed as close as possible to the example in the link 3) increased value in the send call because of protocol fee. Unfoortunatlly, it didn't help, still getting 'Transaction reverted' error. And this started kit is no longer supported.
    – Alex
    Dec 7, 2021 at 10:25

1 Answer 1

0

Finally was ablt to execute fillOrder suscesfully. Actually initial code was almost correct wit few errors - token number should be in encodeERC721AssetData call and token amount (1) - is a value of makerAssetAmount field. And also increase value in the fillOrder call. Here is code sample: const erc721ProxyAddr = deployments[chainId].erc721Proxy; const erc20ProxyAddr = deployments[chainId].erc20Proxy;

    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});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.