简体   繁体   中英

Not able to bridge deployed ERC20 token through POS Bridge using Maticjs, getting this error "execution reverted: ERC20: approve to the zero address"

Here is my code, I have also added the options as well in the approve function which contains the from, to, gasLimit but that also doesn't work for me

const { POSClient, use } = require('@maticnetwork/maticjs');
const { Web3ClientPlugin } = require('@maticnetwork/maticjs-web3');
const HDWalletProvider = require('@truffle/hdwallet-provider');
require('dotenv').config();

use(Web3ClientPlugin);

async function getPOSClient() {
    const posClient = new POSClient();
    return await posClient.init({
        network: 'testnet',
        version: 'mumbai',
        parent: {
            provider: new HDWalletProvider(
                process.env.PVT_KEY,
                process.env.GOERLI_RPC
            ),
            defaultConfig: {
                from: process.env.FROM_ADDRESS,
            },
        },
        child: {
            provider: new HDWalletProvider(
                process.env.PVT_KEY,
                process.env.MUMBAI_RPC
            ),
            defaultConfig: {
                from: process.env.FROM_ADDRESS,
            },
        },
    });
}

async function approveToken() {
    const posClient = await getPOSClient();
    // console.log('🚀 ~ file: index.js:36 ~ approveToken ~ posClient', posClient);

    const erc20Token = posClient.erc20(process.env.ROOT_TOKEN, true);

    const result = await erc20Token.approve('1000');

    const txHash = await result.getTransactionHash();
    console.log('txHash', txHash);

    const receipt = await result.getReceipt();
    console.log('receipt', receipt);
}

approveToken();

The error which I'm getting while approving the token,

Error: execution reverted: ERC20: approve to the zero address
0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002245524332303a20617070726f766520746f20746865207a65726f2061646472657373000000000000000000000000000000000000000000000000000000000000

I have also mapped the token from polygon token mapper portal also. Please give your feedback

This error occurs when you are trying to approve an ERC20 token to the zero address.

Assuming the approve interface is approve(spender, amount) I believe that if you add the approved address to this call const result = await erc20Token.approve(ADDRESS,'1000'); this issue will be resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM