Miss any of our Open RFC calls?Watch the recordings here! »

eth-hooks

1.1.2 • Public • Published

🖇 Hooks

Commonly used Ethereum hooks:

usePoller(fn, delay): runs a function on app load and then on a custom interval

usePoller(() => {
  //do something cool at start and then every three seconds
}, 3000);

useBalance(provider, address, [pollTime]): poll for the balance of an address from a provider

const localBalance = useBalance(localProvider, address);

useBlockNumber(provider,[pollTime]): get current block number from a provider

const blockNumber = useBlockNumber(props.provider);

useContractReader(contract, variableName, [pollTime]): reads a variable from your contract and keeps it in the state

const title = useContractReader(contract, "title");
const owner = useContractReader(contract, "owner");

useEventListener(contract, filter): reads all past events from a smart contract matching a filter and keeps them in the state

const filter = contract.filters.UpdateOwner(null, null))
const ownerUpdates = useEventReader(contract, filter);

useEventReader(contract, eventName, [provider], [startBlock]): listens for events from a smart contract and keeps them in the state

const ownerUpdates = useEventListener(contract, "UpdateOwner", props.localProvider, 1);

useNonce(provider, address): Reads the current nonce of an account

const nonce = useNonce(props.localprovider, address);

useTimestamp(provider): Reads the timestamp of the most recent block

const timestamp = useTimestamp(props.localprovider);

useTokenBalance(contract, address): Reads the ERC20 token balance of an account

const tokenBalance = useTokenBalance(contract, addess);

Install

npm i eth-hooks

DownloadsWeekly Downloads

63

Version

1.1.2

License

MIT

Unpacked Size

52.5 kB

Total Files

40

Last publish

Collaborators

  • avatar