HRE accounts vs. burner ones #1004
-
When using scaffold eth 2 deployment locally, I understand that hardhat creates account and displays their private keys when running "yarn chain". I also understand that scaffold eth creates burner wallets in browser per https://www.quicknode.com/guides/ethereum-development/smart-contracts/introduction-to-scaffold-eth
Testing locally this has created some roadblocks for me because I take the private key I see for the first named account and put it in my metamask wallet with hardhat network configured as below: Network Name: Localhost 8545 I am not sure exactly what goes wrong from here, because even though I see myself connected with the address displayed, after this every time I try to do anything I get an error "Internal JSON-RPC error." which to me means either there isn't enough gas or something is wrong about the network configuration. I used https://scaffold-eth-assistant.streamlit.app/ to search for an answer, this is likely the problem:
My main goal is to be able to interact locally with the contract as the owner and am somehow unable to properly interact as the owner. This explains the issue but doesn't quite solve it. How can I make sure the owner that deploys the contract is the same wallet (burner or not) to interact with it? Ideally the burner wallet would be the same that deploys it. Is resetting the nonce the only way to interact as the owner? Thanks and apologies if I am missing something obvious here. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
Hey @kavehtehrani thanks for this! This will help us to make SE-2 better and more intuitive.
Yes! When you are deploying locally, the
This is probably the nonce error that you mention later (metamask can't detect the correct nonce on the hardhat network). It's annoying, yes. A SE-2 Burner wallet is generated when you load SE-2 for the first time. PK is stored in local storage (ofc this is not secure at all, and burner wallets are only meant to be used locally). The good thing is that you can go fast, and no need to click "sign/send" when broadcasting a tx. Currently, the only way to make 0xf39 (hardhat 0th account) your burner wallet would be to open your browser dev tools, and manually tweak the Some random ideas that we could implement:
Always tricky when playing with PK, even if they are burners! |
Beta Was this translation helpful? Give feedback.
-
I discussed this with someone more knowledgeable than me, and this is another solution he suggested:
|
Beta Was this translation helpful? Give feedback.
-
Oh, if you just want to transfer ownership you can do it directly in the deploy script ( example 1: In a Contract that implements the Ownable pattern await deploy("YourContractOwnable", {
from: deployer,
args: [],
});
const YOUR_BURNER_ADDRESS = "0x0000....."; // Your burner/frontend address
const yourContract = await hre.ethers.getContract<Contract>("YourContractOwnable", deployer);
await yourContract.transferOwnership(YOUR_BURNER_ADDRESS); example 2: If you are using our example contract (just need to pass it in the constructor) const YOUR_BURNER_ADDRESS = "0x0000.....";
await deploy("YourContract", {
from: deployer,
args: [YOUR_BURNER_ADDRESS],
}); |
Beta Was this translation helpful? Give feedback.
-
Most of the time it works without issues. What can help with that error:
|
Beta Was this translation helpful? Give feedback.
-
Amazing, thanks for the suggestions this sorted me out! Btw where is the best place to document this? I looked at https://scaffold-eth-2-docs.vercel.app/ probably could benefit from a FAQ or common issues section. Happy to do a PR but wanted to make sure I haven't missed anything obvious. |
Beta Was this translation helpful? Give feedback.
Hey @kavehtehrani thanks for this! This will help us to make SE-2 better and more intuitive.
Yes! When you are deploying locally, the
deployer
account in00_deploy_your_contract.ts
is always the first (well the 0th :D) hardhat address (0xf39...).This is probably the nonce error that you mention later (metamask can't detect the correct nonce on the hardhat network). It's annoying, yes.
A…