0

I am trying to interact with Matic smart contract on Mumbai chain. The contract address would be - 0x0000000000000000000000000000000000001010.

This code below is calling the approve method.

      const web3 = new Web3(window.ethereum);

      const nonce = await web3.eth.getTransactionCount(
        window.ethereum.selectedAddress
      );

      //get the contract of Matic token
      const contract = new web3.eth.Contract(
        MaticABI as AbiItem[],
        process.env.NEXT_PUBLIC_MATIC_TOKEN_ADDRESS
      );


      const approve = await contract.methods
        .approve(
          process.env.NEXT_PUBLIC_TESTNET_MARKETPLACE_CONTRACT_ADDRESS,
          web3.utils.toBN(data.price)
        )
        .send(
          {
            from: window.ethereum.selectedAddress,
            nonce: nonce,
            gasPrice: web3.utils.toHex(web3.utils.toWei('90', 'gwei')),
            gas: web3.utils.toHex(9000000),
            data: contract.methods.approve(
              process.env.NEXT_PUBLIC_TESTNET_MARKETPLACE_CONTRACT_ADDRESS,
              web3.utils.toBN(data.price)
            ),
          },
          (err: any, res: any) => {.  
             if (err) {
              console.log('err', err);
            } else {
              console.log('res', res);
            }

         })


But each transaction is getting reverted by the EVM. Here is one of the transaction etails, https://mumbai.polygonscan.com/tx/0x9f06e951c5f84654a8bd6202cf3fc792239848aadd7d340777ccd70e65b8af5b

I am not getting how to fix this.

1 Answer 1

0

The token you pay gas with on a chain (so matic on polygon/mumbai, ETH on ethereum, BNB on the BSC) doesnt work the same was as other ERC20 tokens, it doesnt have an approval mechanism, and you can't move it around programatically with transferFrom. If you want to send it to a contract alongside a function call, you need to mark that function payable, and add {value: amount} to the call.

Your Answer

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

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