API Reference

You may want to wrap the Web3Shards RPC endpoints in a web3 provider. Here's how you would do it:

NodeJS (EVM)

'use strict';

const HttpProvider = require("web3-providers-http");
const Web3 = require('web3');

class RPCClient {
    constructor() {
    }

    onChain(_chain) {
        this._provider = new HttpProvider(`https://api.web3shards.io/v1/rpc/${_chain}`, {
            keepAlive: true,
            timeout: 20000,
            headers: [
                {
                    name: 'x-api-key',
                    value: "YOUR_SHARDS_API_KEY"
                }
            ],
        });
        this._web3 = new Web3(this._provider);
        return this;
    }

    isAddress(_address) {
        return this._web3.utils.isAddress(_address);
    }

    async getTransactionReceipt(_tx) {
        return await this._web3.eth.getTransactionReceipt(_tx);
    }

    async getTransaction(_tx, _options=null) {
        return await this._web3.eth.getTransaction(_tx);
    }
}

module.exports = {
  Web3ShardsRPCClient: {
   eth: new RPCClient().onChain('eth'),
   bsc: new RPCClient().onChain('bsc'),
   base: new RPCClient().onChain('base'),
   polygon: new RPCClient().onChain('polygon'),
   shibarium: new RPCClient().onChain('shibarium'),
  }
}

NodeJS (Solana)

'use strict';

const { Connection } = require("@solana/web3.js");

class SolanaRPCClient {
    constructor() {
        this._solana = new Connection("https://api.web3shards.io/v1/rpc/solana"), {
          commitment: "confirmed",
          httpHeaders: [
            {
              name: 'x-api-key',
              value: "YOUR_SHARDS_API_KEY"
            }
          ]
        });
    }

    async getTransaction(_txId, _options=null) {
        return this._solana.getTransaction(_txId, _options);
    }
}

module.exports = SolanaRPCClient;