A Provider is an abstraction of a connection to the Theta Network, providing a concise, consistent interface to standard Theta blockchain node functionality.
Creating a HTTPProvider
This is the default and most commonly used provider.
const chainId = thetajs.networks.ChainIds.Mainnet; // By default, the provider will find the RPC URL to use. However, you can pass your own custom RPC url as the second arg. const provider = new thetajs.providers.HttpProvider(chainId); // If you run a Theta node on your local computer, and want to connect to the local node, you can set up the provider like this const providerForCustomNetwork = new thetajs.providers.HttpProvider('myprivatechain', 'http://localhost:16888/rpc');
const address = "0x000...000"; const account = await provider.getAccount(address);
Get Account Transaction Count
const address = "0x000...000"; const count = await provider.getTransactionCount(address);
Get Block (By Hash)
const blockHash = "0x0000...0000"; const block = await provider.getBlock(blockHash);
Get Block (By Height)
const blockHeight = "7801192"; const block = await provider.getBlock(blockHeight);
Get Current Block Height
const blockHeight = await provider.getBlockNumber();
Updated about 2 years ago