Bware Docs
  • About Bware Labs Decentralized API
  • API Docs
    • Ethereum API
      • RPC
        • eth_getBlockByNumber method
        • eth_getBalance method
        • eth_blockNumber method
        • eth_syncing method
      • Websocket API
        • eth_syncing method
    • Binance Smart Chain API
      • RPC
        • eth_getTransactionByHash method
        • eth_getBlockByNumber method
        • eth_blockNumber method
        • eth_syncing method
        • eth_getBalance method
        • eth_accounts method
        • eth_gasPrice method
      • Websocket API
        • eth_syncing method
    • Avalanche API
      • X-Chain
      • C-Chain
      • P-Chain
      • Keystore API
      • Health API
      • Admin API
      • Info API
      • Metrics API
    • Moonbeam/Moonriver API
      • RPC
        • eth_getBlockByNumber method
        • eth_getBalance method
        • eth_blockNumber method
        • eth_syncing method
      • Websocket
    • Astar/Shiden APIs
      • RPC
        • eth_getBlockByNumber method
        • eth_getBalance method
        • eth_blockNumber method
        • eth_syncing method
      • Websocket
    • Fantom API
      • RPC
        • eth_getBlockByNumber method
        • eth_getBalance method
        • eth_blockNumber method
        • eth_syncing method
      • Websockets
        • eth_syncing method
    • Polkadot API
      • RPC
        • chain_getBlock
        • chain_getHeader
        • system_chainType
        • state_getMetadata
      • Websockets
        • system_chainType
    • Elrond API
      • REST API
        • Get Block By Hash
        • Get Shard Status
  • Tutorials
    • Using Bware Labs Platform
      • Getting a Bware Labs full endpoint
    • Using Bware Labs Endpoint in PolkadotJs
    • Using Bware Labs Endpoint in Metamask
    • Using a Bware Labs endpoint in code
Powered by GitBook
On this page

Was this helpful?

  1. Tutorials

Using a Bware Labs endpoint in code

Listed below you can find a simple code snippet demonstrating how to use a Bware Labs generated endpoint in your javascript code

init: function() {
        ws_provider = new Web3(new Web3.providers.WebsocketProvider ('wss://' 
        + 'eth-api.bwarelabs.com/ws/69231efa-e959-4fb0-ad08-9141cda9ea4d'));
        ws_provider.eth.net.getNetworkType().then((networkID) => {
            switch (networkID) {
                case "main":
                    this.chainID = ChainId.MAINNET;
                    this.network = 'homestead';
                    break;
                case "rinkeby":
                    this.chainID = ChainId.RINKEBY;
                    this.network = 'rinkeby';
                    break;
                default:
                    this.chainID = ChainId.MAINNET;
                    this.network = 'homestead';
            }
            logger.info(`Listening on the ${networkID} network...`);
        });
        oracle_provider = new ethers.providers.WebSocketProvider('wss://'
         + 'eth-api.bwarelabs.com/ws/69231efa-e959-4fb0-ad08-9141cda9ea4d', this.network);
    },
PreviousUsing Bware Labs Endpoint in Metamask

Last updated 3 years ago

Was this helpful?