我有一个简单的合同:
// 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 test给D2打电话
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)输出以下内容:
{
'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)]
}
}发布于 2022-01-19 14:51:45
根据链接的文档,send方法使用options 对象和参数 from、gas、gasPrice、value。
所以对于你的例子来说
await ReentrancyDeployed.methods.depositFunds().send({
value: web3.utils.toWei("10", "ether")
})https://ethereum.stackexchange.com/questions/119344
复制相似问题