question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DX Improvement: add local abi source option

See original GitHub issue

Fetching 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:open
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
krzkaczorcommented, Jan 9, 2022

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.

1reaction
agctycommented, Jan 12, 2022

@krzkaczor yes would love to spend some time on this and write a proposal, give me some time 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Diagnosis and Treatment of Chronic Arterial Insufficiency of ...
These patients are identified by a low ankle-brachial index (ABI), which is determined by dividing the systolic blood pressure measured at the ankle...
Read more >
DX
DX automates a process that captures perceptual and objective measures across the developer experience, shows where friction exists at local team levels and ......
Read more >
Applied Biosystems Veriti™ Thermal Cycler
Insert the USB drive containing the saved run methods and settings into the. USB port on the front of the instrument. 2. Open...
Read more >
Performance Improvements in .NET MAUI
Want to know why .NET MAUI apps boot faster, run smoother, and are smaller? This post break down how we made .NET MAUI...
Read more >
New Build System - Android Studio Project Site
Solve issue with local jar when testing library projects. Fix bug with variant.addJavaSourceFoldersToModel; Add jniLibs folder to source sets for prebuilt .so ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found