简体   繁体   English

无法使用 Maticjs 通过 POS Bridge 桥接部署的 ERC20 令牌,出现此错误“执行已恢复:ERC20:批准到零地址”

[英]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这是我的代码,我还在 approve function 中添加了选项,其中包含从、到、gasLimit,但这对我也不起作用

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.当您尝试将 ERC20 令牌批准到零地址时,会发生此错误。

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');假设批准接口是approve(spender, amount)我相信如果你将批准的地址添加到此调用const result = await erc20Token.approve(ADDRESS,'1000'); this issue will be resolved.这个问题将得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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