Skip to main content

useBlock

useBlock hook is used to fetch the block with the given block number.

You can reach the Block type of Ethers from this link.

Usage

import { useBlock } from "ethylene/hooks";

function App() {
const {
fetchBlock,
} = useBlock({
onSuccess: (block) => {
console.log(block);
},
});

return (
<div>
<button
onClick={async () => await fetchBlock(124124 /* example number */)}
>
Fetch block
</button>
</div>
);
}

API

type Props = {
onSuccess?: (blockNumber: Block) => void;
};

type ReturnType = {
fetchBlock: (blockNumber: number) => Promise<Block>;
};