[英]How to connect binance network in nodejs using web3
我尝试在 Nodejs 中连接 binance 测试网。 这是我的代码。
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('https://data-seed-prebsc-1-s2.binance.org:8545'));
但我得到了错误代码
Error: The current provider doesn't support subscriptions: HttpProvider
at Timeout._onTimeout (E:\test\share1\node_modules\web3-core-subscriptions\lib\subscription.js:176:24)
请让我知道如何解决它。
HTTP 提供程序,不支持订阅。
来源: https://web3js.readthedocs.io/en/v1.7.0/web3.html#value
如果要使用订阅,则需要连接到 websocket 节点 - 而不是 HTTP。
Binance 在其文档页面中推荐了 3rd 方节点提供商列表。 其中一些还支持 websocket 连接。
上面的 web3 部分工作正常。 请尝试以下几行,
var Web3 = require('web3');
const web3_bsc = new Web3('https://data-seed-prebsc-1-s2.binance.org:8545');
然后使用 web3_bsc,访问合约中的函数或执行 web3 支持的任何函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.