javascript 错误:TypeError:无法读取未定义的属性(阅读“hexlife”)

myzjeezk  于 9个月前  发布在  Java
关注(0)|答案(1)|浏览(76)

我只是一个编程的初学者;
无论如何,我试图通过eth网络进行交易,但它会产生无限的错误,请帮助。
const {ether} = require(“ether”);
© 2019 www.infura.io版权所有并保留所有权利

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);
}

字符串
}
return();
我试图发送一个测试交易,但错误仍然存在,如果有人可以检查和解决,请帮助。

pcrecxhr

pcrecxhr1#

根据这个链接,它似乎像你使用醚在错误的方式,尝试改变,

ethers.hexlify(21000)

字符串

ethers.utils.hexlify(21000)

相关问题