JsonRpcProvider constructor

JsonRpcProvider([
  1. String? rpcUrl
])

Create new JsonRpcProvider from rpcUrl.

If rpcUrl is null, JsonRpcProvider will instantiate with default rpc, i.e. http:/\/localhost:8545.


final localRpcProvider = JsonRpcProvider();
final binanceRpcProvider = JsonRpcProvider('https://bsc-dataseed.binance.org/');

print(localRpcProvider); // JsonRpcProvider: http://localhost:8545/
print(binanceRpcProvider); // JsonRpcProvider: https://bsc-dataseed.binance.org/

Implementation

factory JsonRpcProvider([String? rpcUrl]) {
  if (rpcUrl != null) {
    assert(rpcUrl.isNotEmpty, 'Rpc url must not be empty');
    return JsonRpcProvider._(_JsonRpcProviderImpl(rpcUrl), rpcUrl);
  }
  return JsonRpcProvider._(_JsonRpcProviderImpl(), '');
}