将 ETH 从一个帐户转移到另一个帐户时帐户地址无效

问题描述 投票:0回答:0

我有这个节点 js 代码从账户 1 转移金额到账户 2:

const Web3 = require('web3');
const contract = require('truffle-contract');
const TransferContract = contract(require('./build/contracts/Transfer.json'));

async function transferFunds(from, to, amount) {
  // Set up a Web3 provider, e.g. using Ganache or Infura
  const provider = new Web3.providers.HttpProvider('http://127.0.0.1:8545');
  TransferContract.setProvider(provider);

  // Get an instance of the contract deployed at the specified address
  const instance = await TransferContract.deployed();

  // Call the transfer() function on the contract instance
  await instance.transfer(to, amount, { from: from });
}

// Call the transferFunds function with the desired parameters
transferFunds('0xDD6889bcc75510f66566d9f7Ea9C814a5C6043d8', '0xB197d9415Ed9A7ee55d35cAC889C99243c486976', 100);

当我运行代码时,我看到这个错误:

var 错误 = 新错误(消息);

错误:地址无效(arg="account2", coderType="address", 值=100)

原因:'无效地址',
代码:'INVALID_ARGUMENT',
arg:'account2',
编码器类型:'地址',
价值:100

另外,我的代码是这样的:

pragma solidity ^0.8.0;

contract Transfer {
    function transfer(address payable account1, address payable account2, uint amount) public {
        require(address(this).balance >= amount * 2, "Insufficient funds in contract");
        account1.transfer(amount);
        account2.transfer(amount);
    }
}

有人可以告诉我问题是什么吗?

有关更多信息,我在 Truffle 和 Ganache 网络中进行了测试,两个帐户都有足够的信用并且是网络中的真实地址。

node.js ethereum solidity truffle ganache
© www.soinside.com 2019 - 2024. All rights reserved.