错误:类型错误:无法读取未定义的属性(读取“hexlify”)

问题描述 投票:0回答:1

我只是编程初学者;

无论如何,我正在尝试通过 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);
}

}

发送交易();

我试图发送测试交易,但错误仍然存在,如果有人可以检查并解决,请帮忙。

javascript cryptography ethereum blockchain ethernet
1个回答
0
投票

根据此链接,您似乎以错误的方式使用以太币, 尝试改变

ethers.hexlify(21000)

ethers.utils.hexlify(21000)
© www.soinside.com 2019 - 2024. All rights reserved.