Commonly used Ethereum hooks.
yarn add eth-hooks
useOnBlock(
provider,
() => {
//do something cool on each new block
}
);
Runs a function on app load and then on a custom interval.
usePoller(() => {
//do something cool at start and then every three seconds
}, 3000);
Poll for the balance of an address from a provider.
const localBalance = useBalance(localProvider, address);
Get current block number from a provider.
const blockNumber = useBlockNumber(props.provider);
Loads contracts provided in config arg.
const contractsConfig = {
hardhatContracts: hardhatContractsList,
externalContracts: externalContractsList
}
const contracts = useContractLoader(provider, contractsConfig);
Reads a variable from your contract and keeps it in the state.
const balance = useContractReader(contracts, "MyToken", "balanceOf", ["0xde769Dcc704c7Ec4BC2Dd996dfbb997e89995c5a"]);
const owner = useContractReader(contracts, "MyContract", "owner");
Reads all past events from a smart contract and keeps them in the state.
const eventLog = useEventListener(contract, "MyContract", "Event", provider, 0);
Reads the current nonce of an account
const nonce = useNonce(props.localprovider, address);
Reads the timestamp of the most recent block
const timestamp = useTimestamp(props.localprovider);
Reads the ERC20 token balance of an account
const tokenBalance = useTokenBalance(contract, addess);