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

编程入门 行业动态 更新时间:2024-10-04 13:20:29

将 ETH 从一个<a href=https://www.elefans.com/category/jswz/34/1771276.html style=帐户转移到另一个帐户时帐户地址无效"/>

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

我有这个节点 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 网络中进行了测试,两个帐户都有足够的信用并且是网络中的真实地址。

回答如下:

更多推荐

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

本文发布于:2024-05-30 17:08:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770730.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:帐户   地址   转移到   ETH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!