- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我目前正在尝试为我的 Typescript/Node 项目实现一个以太坊 Node 连接。
我正在连接到“Infura” Node 服务器,我需要在其中签署我的本地交易。好吧,无论如何。我正在使用 npm 包“ethereumjs-tx”签署我的交易,一切看起来都很棒。当我使用来自 web3 的“sendRawTransaction”时,我的响应是一个 tx-id,这意味着我的交易应该在区 block 链中准备就绪。好吧……不是
我的签名交易功能如下。
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 ]交易完成=>0xc1520ebfe0a225e6971e81953221c60ac1bfcd528e2cc17080b3f9b357003e34
一切都应该是好的。
有人遇到过同样的问题吗?我希望有人能帮助我。祝你有美好的一天!
最佳答案
在处理了无数次这些问题之后;我很确定您发送的 nonce 太高了。
在这些情况下, Node 仍会向您返回交易哈希,但您的交易将保留在 Node 队列中,不会进入内存池或传播到其他 Node ,UNTIL ,你填补了随机数的空白。
您可以尝试以下方法:
使用 getTransactionCount(address, 'pending') - 包括作为 int Node 队列和内存池的 tx。但是这种方法不可靠,并且不会处理并发请求,因为 Node 需要时间在任何给定时间评估正确的数量。
保留您自己的计数器,而不依赖 Node (除非您检测到一些严重错误)。
对于更严肃的项目,将您的计数器/每个地址保存在数据库级别,并使用锁来处理并发,确保您为每个请求提供正确的随机数。
干杯
关于node.js - 发送原始交易 Ethereum infura nodejs npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44763816/
是否可以使用 web3J 监听 infura 事件?我正在尝试获取事件,但出现错误 Caused by: org.web3j.protocol.core.filters.FilterException
Web3j web3 = Web3j.build(new HttpService());//默认为http://localhost:8545/ 凭证凭证 = WalletUtils.loadCrede
我目前正在尝试为我的 Typescript/Node 项目实现一个以太坊 Node 连接。 我正在连接到“Infura” Node 服务器,我需要在其中签署我的本地交易。好吧,无论如何。我正在使用 n
我使用示例 solidity 代码教程创建了一个合约代币。它有一个名为 transfer 的功能,可以在账户之间发送代币: function transfer(address _to, uint256
我在 Node js 中使用 web3 来创建新的 Web3.providers.HttpProvider 与 infura 项目,其中配置为“要求所有请求的项目 secret ” 在英法拉: htt
web3py 5.3.0 最新文档给出了 eventFilter 的示例 -- https://web3py.readthedocs.io/en/latest/contracts.html#event
我想通过 Web3.py 查看以太坊 txpool 中的实时待处理交易。我不运行本地节点,而是使用 Infura。 根据 Web3.py 的文档,显然一个有三个不同的选项: 使用 TX Pool AP
我不能在我的契约(Contract)上调用创建过滤器,这是我下面的代码。我能够获得契约(Contract)并在其上运行功能,但我无法收听事件: myContract = w3.eth.contract
我使用 infura API 和 ipfs-http-client 在 ipfs 上上传了 jpg 图像。该文件取自 type=file 的输入。事件监听器是 onchange。 // imports
我是一名优秀的程序员,十分优秀!