All calls using "wss://bsc-ws-node.nariox.org:443" and other RPC/WSS endpoints have been failing throughout this week. It just hangs and doesn’t return anything. This is happening in BSC network, but is okay in Polygon network.
On BSC network it happens with both Ethers.js and Web3.js libraries. Below is a sample implementation using ethers.js
Note that this has been tested from a NodeJS server on an AWS server located in London. Then subsequently it was tested on a Moralis server based in Singapore, but obtained the same results (hanging & no return).
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();