The best starting point that I found:
The Complete Guide to Full Stack Ethereum Development
Random things:
- Hardhat docs don't list the networks available for the
networks
field in the hardhat.config.js
file.
- Hardhat docs don't tell you how to deploy to production.
- You'd think that
ethers
would have a way to get your MetaMask accounts, but it doesn't. I assumed it's purpose was to be a wrapper around the JSON RPC stuff. But that's not completely true. To get a list of connected accounts, you have to do this:
await window.ethereum.request({ method: 'eth_requestAccounts' });
- Hardhat's
hardhat-waffle
testing framework injects ethers
into the runtime environment that is used in scripts and hardhat tasks.
- Hardhat not setting the provider properly? See bug. In general, provider
hardhat-gas-reporter
not reporting gas price because script completes execution before gas prices from API return. See bug
- Error when using
ethers
to read a public variable from a contract, but only on mainnet
cannot estimate gas; transaction may fail or may require manual gas limit (error={"code":-32000,"message":"execution reverted"}, method="call", transaction={"to":"0xDD13Be9D65a5ca2651344B4C05903B88f013af2E","data":"0x06fdde03","accessList":null}
- Similar issue, where the real problem was that the account doesn't hold any Ether
- Undocumented functions
- This issue comment talks about using the undocumented
provider.getFeeData()
function to help resolve a bug that might help with the issue I'm having?
Lots of pieces
To get a React Ethereum project going, there's a lot of moving pieces and most tutorials focus on just getting things working without explaining what each piece does and why. It's hard to build up a mental model of what all the pieces do and what they're for.
Here's the pieces you'll need:
- A way to run a local Ethereum node. Hardhat has this via
npx hardhat node
.
- An Ethereum account (that you'll use to deploy from / interact with your dapp).
- Next, you'll want to have a way to develop some smart contracts and test that they work. I know it's tempting to see something on screen, but I've been burned every time I wanted to jump to get something visual on screen. Many of the libraries aren't mature, so you'll likely run into all sorts of issues.
- The easiest way to do this is to install hardhat and get it configured using their getting started tutorial.
- This will show you how to write a contract, deploy it locally, and write some unit tests. This sounds boring, but I wouldn't skip it.
- I know you wanna deploy something to production quickly, but hold your horses.
- Once you can run some unit tests, you're ready to learn a little bit about ethers
- Ethers
- The MetaMask browser extension that you'll connect to the local Ethereum node/network (I don't see the difference in this context) and login using the private key generated by the local eth node for testing.
- Now you're sort of ready to develop locally. When you connect to existing production dapps you just need MetaMask (and it's connected to mainnet by default). What we've done now is setup our local environment so that we can interact with our local dapp once we start building it.