menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Truffle Suite

Sweet tools for smart contracts

Channels
Team

ganache-cli unlock any account

August 26, 2020 at 10:54am

ganache-cli unlock any account

August 26, 2020 at 10:54am
https://github.com/trufflesuite/ganache-cli/issues/143 this is an old link, but could anyone highlight the -u flag, I know it can be used to send transactions as any account, but how can I unlock an account after ganache-cli has started? same answer for forking as well?

August 26, 2020 at 11:28am
some additional context, I am using ethers to communicate to the forked blockchain. I need to know how to send transactions from an address , which I don't have a private key too
to*
const options = {
"port":8545,
"default_balance_ether":10000,
"total_accounts":10,
"fork":"https://mainnet.infura.io/v3/xxx",
"network_id":1,
"locked":false,
"ws":true,
"account_keys_path":"./accounts.json",
"unlocked_accounts":["0x6b175474e89094c44da98b954eedeac495271d0f"]
}
Edited
const provider = new ethers.providers.Web3Provider(ganache.provider(options))
here's what happens when I try to unlock it
when I unlock an account that is generated
In general you need to have unlocked the account to access it. The -u options lets you unlock during startup. I think you will just need to use a provider that allows you to access the account you are interested in by means of a mnemonic or private keys.
I hope that was helpful. The one I'm most familiar with is our package /hdwallet-provider. For that you need a mnemonic or private keys to use the account.
hmm, but the docs of ganache-cli say that I can use any account for testing/debugging
the -u flag is equivalent to unlocked_accounts in the options yes?
(eggplantzzz)
Yes but you need to unlock it on Ganache startup or afterwards with your provider.
I'm not sure what you mean by "... is equivalent to unlocked_accounts"
Can you clarify a little bit more?
pls refer to this for what I mean by unlocked_accounts
also, could you send a snippet on how to unlock it with my provider after ganache has started?
(eggplantzzz)
this is what happens when i try to unlock an account
I can use signer.sendUncheckedTransacion for the unlocked account in that array, my question is how do I add more accounts to the unlocked_accounts array after ganache has started?
(tcoulter) I think you worked on this on https://github.com/trufflesuite/ganache-cli/issues/143?

August 27, 2020 at 2:58pm
I need help with this asap!
Show more messages