Is there a way to unlock all the accounts form a forked chain? #3603
-
The documentation talks about unlocking specific accounts from a forked chain by specifying the account numbers during the start of the program. However, I want to be able to specify the accounts to unlock either while running Ganache or just unlock all the accounts from the forked chain in the beginning. I saw that there was a pull request raised for it and it was also merged (with a re-opened pull request), but I'm not sure how to use that feature. Does that feature still exist in the latest version of ganache? If yes, how do I use that? Are there any specific flags for it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @surajsjain, thanks for the question! You can add any arbitrary account to Ganache using the const address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"; // any address can go here :)
const passphrase = "passphrase"
const result = await provider.send("evm_addAccount", [address, passphrase] );
console.log(result); The address is now added to the Note, at this point the account is only able to be used by To unlock the account, you can now use const isUnlocked = await provider.send("personal_unlockAccount", [address, passphrase] );
console.log(isUnlocked); Now the account is unlocked and will work with So, to put it all together, you can use this to add an account to Ganache and unlock it: // add some account to Ganache
const address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"; // any address can go here :)
const passphrase = "passphrase"
const result = await provider.send("evm_addAccount", [address, passphrase] );
console.log(result);
// unlock the account
const isUnlocked = await provider.send("personal_unlockAccount", [address, passphrase] );
console.log(isUnlocked);
// use the account however you want
const hash = await provider.send("eth_sendTransaction", [ { from: address, to: anotherAddress, gas: "0xfffff" } ] ); |
Beta Was this translation helpful? Give feedback.
Hi @surajsjain, thanks for the question! You can add any arbitrary account to Ganache using the
evm_addAccount
method:The address is now added to the
personal
namespace in Ganache, which means that sending and and signing transactions can be done viapersonal_sendTransaction
andpersonal_signTransaction
. These methods are identical toeth_sendTransaction
andeth_signTransaction
, except they have an additional parameter for the passphrase that was originally used to add…