简体   繁体   English

为什么所有对 BSC 网络的 ethersjs 和 web3js 调用都失败了?

[英]Why are all ethersjs & web3js calls to BSC network failing?

All calls using "wss://bsc-ws-node.nariox.org:443" and other RPC/WSS endpoints have been failing throughout this week.本周所有使用“wss://bsc-ws-node.nariox.org:443”和其他 RPC/WSS 端点的调用都失败了。 It just hangs and doesn't return anything.它只是挂起,不返回任何东西。 This is happening in BSC network, but is okay in Polygon network.这发生在 BSC 网络中,但在 Polygon 网络中是可以的。

On BSC network it happens with both Ethers.js and Web3.js libraries.在 BSC 网络上,它发生在Ethers.jsWeb3.js库中。 Below is a sample implementation using ethers.js下面是使用 ethers.js 的示例实现

Note that this has been tested from a NodeJS server on an AWS server located in London.请注意,这已经在位于伦敦的 AWS 服务器上的 NodeJS 服务器上进行了测试。 Then subsequently it was tested on a Moralis server based in Singapore, but obtained the same results (hanging & no return).随后,它在位于新加坡的 Moralis 服务器上进行了测试,但获得了相同的结果(挂起且无法返回)。

code:代码:

const ethers = require('ethers');
console.log(`ethers version: ${ ethers.version }`);//5.4.4
const Web3 = require('web3');

const _ = require('lodash');

const dotenv =  require("dotenv");
dotenv.config();

//const add = “ wss://ws-matic-mainnet.chainstacklabs.com/”;   //“https://polygon-rpc.com”; //polygon       // swing 1
const add = "wss://bsc-ws-node.nariox.org:443"; //bsc
console.log(`add: ${ add }`);
const mnemonic_3 = process.env.YOUR_MNEMONIC_3 //''; //privatekey GANTI // add own private key to test
const provider = new ethers.providers.WebSocketProvider( add );
const wallet_3 = new ethers.Wallet(mnemonic_3);
const account_3 = wallet_3.connect(provider);
let awaits = async () => {

    console.log(`account: ${ await account_3.getAddress() }`);
    console.log(`wallet: ${ await wallet_3.getAddress() }`);
    //console.log(`account: ${ await account_3.provider.getSigner().getAddress() }`);
    console.log(`signer: ${ account_3 == (await account_3.provider.getSigner()) }`);
    console.log(`signer: ${ wallet_3 == (await account_3.provider.getSigner()) }`);
    //console.log(`provider: ${ await account_3.provider.getAddress() }`);    // not a function


    // A Human-Readable ABI; for interacting with the contract, we
    // must include any fragment we wish to use
    const abi = [
        // Read-Only Functions
        "function balanceOf(address owner) view returns (uint256)",
        "function decimals() view returns (uint8)",
        "function symbol() view returns (string)",

        // Authenticated Functions
        "function transfer(address to, uint amount) returns (bool)",

        // Events
        "event Transfer(address indexed from, address indexed to, uint amount)"
    ];

    // This can be an address or an ENS name
    //const address = "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270";   // matic - polygon // swing 2
    const address = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";   // bnb - bsc

    // Read-Only; By connecting to a Provider, allows:
    // - Any constant function
    // - Querying Filters
    // - Populating Unsigned Transactions for non-constant methods
    // - Estimating Gas for non-constant (as an anonymous sender)
    // - Static Calling non-constant methods (as anonymous sender)
    const erc20 = new ethers.Contract(address, abi, provider);
    console.log(`decimals: ${ await erc20.decimals() }`);

    // Read-Write; By connecting to a Signer, allows:
    // - Everything from Read-Only (except as Signer, not anonymous)
    // - Sending transactions for non-constant functions
    const erc20_rw = new ethers.Contract(address, abi, account_3)
    console.log(`decimals: ${ await erc20_rw.decimals() }`);

}
awaits();

I changed provider to Chainstack, works great now.我将提供者更改为 Chainstack,现在效果很好。 Steps to sign up are outlined here 此处概述了注册步骤

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM