首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问web3脚本中的txpool?

如何访问web3脚本中的txpool?
EN

Ethereum用户
提问于 2017-08-11 01:48:03
回答 1查看 6.9K关注 0票数 4

我运行了一个testnet (恢复) ethereum节点。我想了解txpool的内容。使用geth控制台,我可以访问变量txpool。

我的问题是如何在web3脚本中访问这个变量?

代码语言:javascript
复制
Web3 = require("web3");
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

如下所示:

代码语言:javascript
复制
pendingTx = web3.txpool ?

pendingTx = web3.eth.txpool ?

它们都是未定义的..。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2018-05-07 13:21:20

使用Web3 1.0.0,很容易自己实现它:

代码语言:javascript
复制
var Web3 = require('web3');
var web3 = new Web3('ws://127.0.0.1:8546');
web3.eth.extend({
  property: 'txpool',
  methods: [{
    name: 'content',
    call: 'txpool_content'
  },{
    name: 'inspect',
    call: 'txpool_inspect'
  },{
    name: 'status',
    call: 'txpool_status'
  }]
});

然后正常使用:

代码语言:javascript
复制
web3.eth.txpool.status().then(console.log).catch(console.error)

输出:

代码语言:javascript
复制
{pending: "0x0", queued: "0x0"}

同样,您可以使用扩展 Web3来调用任何其他“缺失”JSON RPC

票数 4
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/24127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档