繁体   English   中英

发送 ERC20 代币不起作用:地址无效

[英]send ERC20 tokens not working: invalid address

这是我的 javascript 代码:我发送到的地址是用户在应用程序上输入的地址。 调用者(当前选择的元掩码地址有足够的 ERC20 代币)

lookupVoterInfo: function() {
   let toAddress = $("#voter-info").val();
   Voting.deployed().then(function(contractInstance) {
     contractInstance.transfer(toAddress, 10);
   })

MyERC20 合约:

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

import "../openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import "../openzeppelin-contracts/contracts/math/SafeMath.sol";

contract MyERC20 is ERC20 {
    uint256 public INITIAL_SUPPLY = 20000;
constructor() ERC20("MyToken", "MYT") {
        _mint(msg.sender, INITIAL_SUPPLY);
    }
}

错误信息:

在此处输入图像描述

我通过执行以下操作解决了它:您需要指定汽油费和帐户地址。

contractInstance.approve(web3.currentProvider.selectedAddress, 100, {gas: 1000000, from: web3.eth.accounts[0]}); contractInstance.transferFrom(web3.currentProvider.selectedAddress, toAddress, 10, {gas: 1000000, from: web3.eth.accounts[0]});

暂无
暂无

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

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