API Reference
React Hooks
useWeb3Injected
function useWeb3Injected(options?: Web3ContextOptions): Web3Context
Returns Web3Context built from an injected provider like MetaMask. Will re-render on accounts, network, and connection change.
useWeb3Network
function useWeb3Network(connection: string, options?: Web3ContextOptions)
: Web3Context
Returns Web3Context built from a connection string like Infura or a private node. Will re-render on accounts, network, and connection change.
Helpers
WebContextOptions
export interface Web3ContextOptions {
timeout: number;
pollInterval: number;
gsn: boolean | object;
}
timeout
specifies wait time for underlying web3 provider calls before considering them failed.
pollInteral
is how often data will be polled from an underlying web3 provider. For network providers you might want to set this parameter manually to control a network load.
gsn
if set a GSN provider will be use. Pass an object to set GSN provider options.
Web3Context
Web3Context
class is reponsible for polling web3 providers, firing events, enabling GSN, and keeping data fresh. Typically you shouldn’t call any methods on Web3Context yourself. Use React Hooks or helper methods.
Properties
accounts
public accounts: string[] | null;
Provides an instant access to the accounts of a web3 provider. If an array is empty then accounts either locked or not avaiable on a web3 provider.
Methods
startPoll
public startPoll(): void
Starts polling data from web3 provider and firing events on change. Typically you shouldn’t call this method directly.
stopPoll
public stopPoll(): void
Stops polling data and firing events. Typically you shouldn’t call this method directly.
poll
public async poll(): Promise<void>
Updates data and fires events only once. Typically you shouldn’t call this method directly.
requestAuth
public async requestAuth(): Promise<string[]>
Request access to the accounts of an underlying web3 provider according to the [EIP-1102](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1102.md). Typically you shouldn’t call this method directly.