简体   繁体   中英

send ERC20 tokens not working: invalid address

Here is my javascript code: The address I'm sending it to is input address from user on app. The caller (currently selected metamask address has enough ERC20 tokens)

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

MyERC20 Contract:

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

error message:

在此处输入图像描述

I solved it by doing the following: You need to specify the gas fee and the account address.

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

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