Search code examples
blockchainethereumtruffleweb3-java

Use ganache accounts in web3j


When trying to use https://github.com/web3j/sample-project-gradle I encounter this code:

    // We then need to load our Ethereum wallet file
    // FIXME: Generate a new wallet file using the web3j command line tools https://docs.web3j.io/command_line.html
    Credentials credentials =
            WalletUtils.loadCredentials(
                    "<password>",
                    "/path/to/<walletfile>");
    log.info("Credentials loaded");

I wanted to use network created by ganache-cli. I did successfully connect to the network but I can't find the wallet files. Is there a way to use here accounts generated by ganache-cli?


Solution

  • ganache-cli is a personal blockchain. It does not create wallet file, rather provides private key to load credentials.

    Credentials credentials = Credentials.create("0x78c0cf2c035dda3c46953fb7b926f8ece0aa8bfed6c012e33d5e289e6e0c1ebc");