Ganache-cli: Keystore location - Using Go to Deploy Contracts to Ganache

Created on 12 Jul 2018  路  6Comments  路  Source: trufflesuite/ganache-cli

Where to find keystore of running Ganash instance?

I need to get a key JSON to put it in my Go code, like this: https://vincentserpoul.github.io/post/binding-ethereum-golang/ in order to deploy a contract from Go

question

Most helpful comment

@seesemichaelj @drasko Also want to thank you for this... it worked like a charm. I was not aware of the HexToECDSA function and spent like 2 hours trying to figure out how to convert the private key string from Ganache into a PrivateKey object. Thanks again!

All 6 comments

Hey @drasko! Unfortunately Ganache doesn't have a keystore folder like geth/parity. Due to the nature of Ganache, you'd likely use NewKeyedTransactor instead: https://github.com/ethereum/go-ethereum/blob/f8f428cc18c5f70814d7b3937128781bac14bffd/accounts/abi/bind/auth.go#L47

The method the tutorial you referenced is using an encrypted key. The private key's that ganache-cli output (which are in the console output when you start ganache-cli) are unencrypted and can be used directly (which is what NewKeyedTransactor looks like it supports).

Looks like you can get the Go key using crypto.HexToECDSA("insertprivatekeyherefromganacheclioutputwithoutpreceding0x"). See https://github.com/ethereum/go-ethereum/blob/1836366ac19e30f157570e61342fae53bc6c8a57/contracts/ens/ens_test.go#L31 and line 39 for an example

Hope this helps!

@seesemichaelj fantastic help there - worked like a charm!

Apparently I missed something! You can also add the following option to the cli to get out the keystore format:
--acctKeys="./ganache-accounts.json"

this does not produce needed keystore format with "crypto" field. Looks like this is some Ganache-specific JSON to describe created accounts.

Bummer; well thanks for following up and saying it doesn't work. We don't currently have any plans to output it in this JSON format, but the first method I presented should be sufficient.

@seesemichaelj @drasko Also want to thank you for this... it worked like a charm. I was not aware of the HexToECDSA function and spent like 2 hours trying to figure out how to convert the private key string from Ganache into a PrivateKey object. Thanks again!

Was this page helpful?
0 / 5 - 0 ratings