【发布时间】:2022-08-24 00:27:57
【问题描述】:
我正在运行以下 javascript 文件并使用 web3js 在 Goerli 上调用智能合约 (0xF3885ca057a42B10b6cb432B816FE11426a2E369):
const Web3 = require(\"web3\");
// Loading the contract ABI
// (the results of a previous compilation step)
const fs = require(\"fs\");
const { abi } = JSON.parse(fs.readFileSync(\"EtherSplitter.json\"));
async function main() {
// Configuring the connection to an Ethereum node
const network = process.env.ETHEREUM_NETWORK;
const web3 = new Web3(
new Web3.providers.HttpProvider(
`https://${network}.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
)
);
// Creating a signing account from a private key
const signer = web3.eth.accounts.privateKeyToAccount(
process.env.SIGNER_PRIVATE_KEY
);
web3.eth.accounts.wallet.add(signer);
// Creating a Contract instance
const contract = new web3.eth.Contract(
abi,
// Replace this with the address of your deployed contract
process.env.ETHERSPLITTER_CONTRACT
);
// Issuing a transaction that calls the splitEther method
const tx = contract.methods.splitEther([\"0xdF8b511C3682b093736318A67Fcc2FEC6772D1a6\",\"0x1E2eBeBB3348B1FeFC29239c20Df1c78668180Cc\"]);
const receipt = await tx
.send({
from: signer.address,
value: 1e15, // IS THIS CORRECT? IF NOT, HOW DO I SPECIFY VALUE FOR SEND
gas: await tx.estimateGas(),
})
.once(\"transactionHash\", (txhash) => {
console.log(`Mining transaction ...`);
console.log(`https://${network}.etherscan.io/tx/${txhash}`);
});
// The transaction is now on chain!
console.log(`Mined in block ${receipt.blockNumber}`);
}
require(\"dotenv\").config();
main();
智能合约是:
contract EtherSplitter {
function splitEther(address payable[] memory recipients) public payable {
uint fee = 10;
recipients[0].transfer(msg.value * fee / 100);
recipients[1].transfer(msg.value * (100 - fee) / 100);
}
receive() external payable {
}
}
执行正在恢复并出现以下错误:
users/myusername/demo-eth-tx/node_modules/web3-core-helpers/lib/errors.js:28
var err = new Error(\'Returned error: \' + message);
我认为我错误地使用了发送,并且错误地指定了发送值。我该如何解决?