我只是编程初学者;
无论如何,我正在尝试通过 eth 网络进行交易,但它给出了无限的错误,请帮忙。
const { 以太币 } = require("以太币");
异步函数sendTransaction() { const ethereumNodeUrl = 'https://mainnet.infura.io/v3/085077982f094073a03893b9e3e338ec';
const provider = ethers.getDefaultProvider('homestead', {
infura: ethereumNodeUrl,
});
const senderAddress = '0x0112fa4CB650dCa6eE0f9Bd74106EbB27C382622';
const recipientAddress = '0xA705f5c1dEb081D329EdD2d2ED6817f161Cfd1F0';
const privateKey = 'WALLET_PVT_KEY';
try {
const wallet = new ethers.Wallet(privateKey, provider);
const tx = {
to: recipientAddress,
value: ethers.parseEther('0.1'), // Change the value as needed
gasLimit: ethers.hexlify(21000), // Adjust gas limit accordingly
gasPrice: ethers.parseUnits('50', 'gwei'), // Adjust gas price accordingly
};
const signedTx = await wallet.sendTransaction(tx);
console.log(`Transaction hash: ${signedTx.hash}`);
} catch (error) {
console.error('Error:', error);
}
}
发送交易();
我试图发送测试交易,但错误仍然存在,如果有人可以检查并解决,请帮忙。