首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能用醚调用方法

不能用醚调用方法
EN

Ethereum用户
提问于 2022-01-19 13:21:58
回答 1查看 47关注 0票数 0

我有一个简单的合同:

代码语言:javascript
复制
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Reentrancy {
    mapping(address => uint256) public balances;

    function depositFunds() external payable {
        balances[msg.sender] += msg.value;
    }
}

我无法用truffle testD2打电话

代码语言:javascript
复制
let Reentrancy = artifacts.require("Reentrancy")

it('test', async () => {
    let ReentrancyDeployed = await Reentrancy.deployed()
    await ReentrancyDeployed.methods.depositFunds().send(web3.utils.toWei("10", "ether"))
}

看起来ReentrancyDeployed.methods.depositFunds是未定义的,但根据文件,这是正确的方法。

出什么问题了?

<#>编辑

console.log(ReentrancyDeployed.methods)输出以下内容:

代码语言:javascript
复制
{
  'balances(address)': [Function (anonymous)] {
    call: [Function (anonymous)],
    sendTransaction: [Function (anonymous)],
    estimateGas: [Function (anonymous)],
    request: [Function (anonymous)]
  },
  'depositFunds()': [Function (anonymous)] {
    call: [Function (anonymous)],
    sendTransaction: [Function (anonymous)],
    estimateGas: [Function (anonymous)],
    request: [Function (anonymous)]
  }
}
EN

回答 1

Ethereum用户

发布于 2022-01-19 14:51:45

根据链接的文档,send方法使用options 对象参数 fromgasgasPricevalue

所以对于你的例子来说

代码语言:javascript
复制
await ReentrancyDeployed.methods.depositFunds().send({
  value: web3.utils.toWei("10", "ether")
})
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/119344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档