发送原始交易以太坊infura nodejs npm

我目前正试图实现以太坊节点连接到我的手稿/节点项目。

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

我的符号交易function如下。

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

在“signTransactionLocally”中使用的函数:

  private getGasLimit2(hex: boolean = false) { const latestGasLimit = this.web3.eth.getBlock("latest").gasLimit; return hex ? this.toHex(latestGasLimit) : latestGasLimit; } private getNonce(hex:boolean = false, wallet: string = "0x60a22659E0939a061a7C9288265357f5d26Cf98a") { return hex ? this.toHex(this.eth().getTransactionCount(wallet)) : this.eth().getTransactionCount(wallet); } 

运行我的代码如下所示:

 this.dumpInformations(); const signedTransaction = this.signTransactionLocally(this.toHex((this.getMaxAmountToSend(false, "0x60a22659E0939a061a7C9288265357f5d26Cf98a") / 3 )), "0x38bc48f1d19fdf7c8094a4e40334250ce1c1dc66" ); console.log(signedTransaction); this.web3.eth.sendRawTransaction("0x" + signedTransaction, function(err: any, res: any) { if (err) console.log(err); else console.log("transaction Done=>" + res); }); 

因为sendRawTransaction导致控制台日志:[Node] transaction Done => 0xc1520ebfe0a225e6971e81953221c60ac1bfcd528e2cc17080b3f9b357003e34

一切都应该是好的。

有没有人有同样的问题? 我希望有人能帮助我。 祝你今天愉快!