小编Ste*_*mer的帖子

发送原始交易 Ethereum infura nodejs npm

我目前正在尝试实现到我的 Typescript/Node 项目的以太坊节点连接。

我正在连接到我需要在本地签署我的交易的“Infura”节点服务器。好吧,无论如何。我正在使用 npm 包“ethereumjs-tx”签署我的交易,一切看起来都很棒。当我使用来自 web3 的“sendRawTransaction”时,我的响应是一个 tx-id,这意味着我的交易应该已经在区块链中了。嗯……不是

我的标志交易功能如下。

private signTransactionLocally(amountInWei: number, to: string, privateKey: string = <PRIVATE_KEY>, wallet: string = <MY_WALLET>) {
        const pKeyBuffer = Buffer.from(privateKey, "hex");

        const txParams = {
            nonce: this.getNonce(true,wallet),
            //gas: this.getGasPrice(true),
            gasLimit: this.getGasLimit2(true),
            to: to,
            value: amountInWei,
            data: '0x000000000000000000000000000000000000000000000000000000000000000000000000',
            chainId: "0x1"
        };

        // console.log(JSON.stringify(txParams));
        const tx = new this.ethereumTx(txParams);
        tx.sign(pKeyBuffer);
        return tx.serialize().toString("hex");

    }
Run Code Online (Sandbox Code Playgroud)

在“signTransactionLocally”中使用的函数:

    private getGasLimit2(hex: boolean = false) {
        const latestGasLimit = this.web3.eth.getBlock("latest").gasLimit;
        return hex ? this.toHex(latestGasLimit) : latestGasLimit;
    }
    
        private getNonce(hex:boolean = …
Run Code Online (Sandbox Code Playgroud)

node.js blockchain ethereum web3js

5
推荐指数
1
解决办法
1546
查看次数

标签 统计

blockchain ×1

ethereum ×1

node.js ×1

web3js ×1