DX Improvement: add local abi source option
See original GitHub issueFetching ABIs from etherscan or sourcify is great but only works if the contracts are already deployed and verified. But how do you work with contracts that are not yet deployed?
Would like to build different frontend environments: local (npx hardhat node) / staging (e.g goerli) / production (e.g mainnet)
I’m working on some local smart contracts with hardhat and don’t want to deploy them just yet, I just want to play around locally and have my frontend pick up all the right types. Seems like I can’t do that at the moment (or haven’t found a way by looking through the docs).
Something like that would improve DX by 100x
const config: EthSdkConfig = {
contracts: {
mainnet: {
dai: "0x4a436073552044D5f2f49B176853ad3Ad473d9d6",
},
goerli: {
dai: "0x3a436073552044D5f2f49B176853ad3Ad473d9d6",
},
local: {
dai: {address: "0x5a436073552044D5f2f49B176853ad3Ad473d9d6", abi: "../dai.json"},
},
},
networkIds: {
local: 1337
},
};
Basically allowing you to opt in to use a local abi for any contract. There is also the possibility of defining that all local contracts should fetch the abi from a local source and do some filename lookup but having a granular approach that lets you choose where the abi is coming from for each contract is better IMO because you might be working with some contract that is not verified for some reason but you still have the abi. So you could mix verified contracts on mainnet with unverified ones where you still have the abi for example. (Note: All contracts should be verified but this use case is still valid IMO)
For context, to use this in a frontend I’d probably create a custom hook that gets the current network name from an env file and returns the correct SDK.
Like this (pseudo-code):
function useSDK() {
const { library } = useWeb3React();
// if a signer is injected by web3-react via Metamask use that, if not, use a default provider
const signerOrProvider = library ? library : getDefaultProvider();
if (process.env.NEXT_PUBLIC_NETWORK === "mainnet") {
return getMainnetSDK(signerOrProvider);
}
if (process.env.NEXT_PUBLIC_NETWORK === "goerli") {
return getGoerliSDK(signerOrProvider);
}
if (process.env.NEXT_PUBLIC_NETWORK === "local") {
return getLocalSDK(signerOrProvider);
}
}
Let me know if I can help in any way to support this 😃
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Thanks for spending time writing this down. I like this proposal. It’s inline with how I was thinking about it. The problem is that each network can list different addresses + some contracts might now be even deployed on any network and requires providing ABI manually (we could allow specifying abi path instead of address for a special network called “local”).
It would be awesome if you would want to develop this feature. As a next step I would love to see a detailed written proposal and discuss with exact code examples etc.
@krzkaczor yes would love to spend some time on this and write a proposal, give me some time 😃