SWR-eth
An util to use SWR with Ethereum
Configure in your project
You can use SWRConfig
to have a global fetcher capable of retrieving basic Ethereum information (e.g. block, getBalance)
or directly interact with a smart contract
;;;; const ABIs = '0x6b175474e89094c44da98b954eedeac495271d0f' ERC20ABI const Wallet = { const chainId account library activate active = useWeb3React<Web3Provider> const onClick = { } return <div> <div>ChainId: chainId</div> <div>Account: </div> active ? <div>✅ </div> : <button type="button" onClick=onClick> Connect </button> active && <SWRConfig value= fetcher: > <EthBalance /> <TokenList chainId=chainId /> </SWRConfig> </div> }
Interact with basic method
const { data: balance } = useSWR(['getBalance', 'latest'])
You can use all the methods provided by a Web3Provider from Ether.js
Interact with a smart contract
const { data: balance } = useSWR(['0x6b175474e89094c44da98b954eedeac495271d0f','balanceOf', 'latest'])
You can use all the methods provided by a contract as long as you have provided the ABI associated to the smat contract
address when you configured the ethFetcher
Example
A minimal example is availablehere
Related projects
Licence
Licensed under MIT.