useBlockNumber
useBlockNumber
hook is used to fetch the block number from the provider
Usage
import { useBlockNumber } from "ethylene/hooks";
function App() {
const {
blockNumber,
fetchBlockNumber,
} = useBlockNumber();
return (
<div>
<button onClick={async () => await fetchBlockNumber()}>
Fetch block number
</button>
</div>
);
}
API
type Props = {
direct?: boolean; // Whether to fetch the block number on component mount
deps?: any[]; // Fetch block number when the values inside deps change
onSuccess?: (blockNumber: number) => void;
};
type ReturnType = {
fetchBlockNumber: () => Promise<number>;
blockNumber: number;
setBlockNumber: (to: number) => void;
};