aboutlo / ether-swr

Ether-SWR is a React hook that fetches Ethereum data. It streamlines the chores to keep the internal state of the Decentralized App (DApp), batches the RPC calls to an Ethereum node and cache the responses
MIT License
138 stars 12 forks source link

Is it possible to do a static call with the useEtherSWR hook? #24

Open jviray opened 2 years ago

jviray commented 2 years ago

Ethers.js allows you to call a state-changing method as a read-only function w/ callStatic.

The ethers.js docs say that using Contract.callStatic.METHOD_NAME will basically ask a node to pretend that a call is not state-changing and return the result. The method will effectively become a read-only function.

So if the function I'm trying to call is mint(), can I use the useEtherSWR to do a TokenContract.callStatic.mint()?

aboutlo commented 2 years ago

hey @jviray interesting question. The default ether-js-fetcher.ts doesn't support that. You could create a custom one but I would suggest using directly Etherjs I don't see it as a very common use case.