提问人:Ngọc Minh Nguyễn 提问时间:11/14/2023 更新时间:11/14/2023 访问量:22
InvalidResponseError:返回错误:方法eth_sendTransaction不存在/不可用
InvalidResponseError: Returned error: The method eth_sendTransaction does not exist/is not available
问:
我正在尝试使用 web3 在 BSCtest 上与智能合约进行交互。我认为错误发生在这一行中
rs = await TokenContract.methods.transfer(receiverAddress, 100000).send({
from: myAddress,
gas: 3000000
})
完整代码:
require('dotenv').config();
const {Web3} = require('web3');
myPrivateKey = process.env.PRIVATE_KEY;
const TokenAddress = "0x026e6631A3514e0B52c3D33c09D52Ab9574C2703";
const TokenAbi = [...]
myAddress = "0xb5253E9D3Ec90b7887Eec27a7F280D176Fd542A3";
receiverAddress = "0xF37ab5FC6D6093E281Be2129e10D5f86e2f20E11";
async function interact(){
web3 = new Web3("https://data-seed-prebsc-2-s3.binance.org:8545");
TokenContract = await new web3.eth.Contract(TokenAbi, TokenAddress);
// myBalance = await TokenContract.methods.balanceOf(myAddress).call();
// console.log(myBalance);
await web3.eth.accounts.wallet.add({
privateKey: myPrivateKey,
address: myAddress
});
receiverBalanceBefore = await TokenContract.methods.balanceOf(receiverAddress).call();
rs = await TokenContract.methods.transfer(receiverAddress, 100000).send({
from: myAddress,
gas: 3000000
})
receiverBalanceAfter = await TokenContract.methods.balanceOf(receiverAddress).call();
console.log(receiverBalanceBefore, receiverBalanceAfter);
}
interact();
我在堆栈溢出时遇到了另一个类似的错误,例如将 0 传递给值参数。
contract.methods.test().send({from:account, value: 0})
但它对我不起作用
答: 暂无答案
评论