简体   繁体   中英

Using java web3j to create wallet but how then connect to private running blockchain?

I'm using the java web3j lib and creating a new wallet file using:

WalletUtils.generateFullNewWalletFile()

With:

Web3j web3 = Web3j.build(new HttpService());

... I'm connecting to my local private blockchain running geth.

The question is. How can I add some test either to my wallet and what is the context between my local created wallet and the geth client I'm running.

How can I connect the web3j created wallet with to the geth client?

With:

WalletUtils.loadCredentials()

.. I am able the get the wallets public address but the account is not listed in the geth client when I am using:

web3.ethAccounts().send().getAccounts()

How this fits together?

Initial ether needs to be specified in genesis.json when you initialize your private blockchain.

A simple example:

{
    "config": {
        "chainId": 29462
    },
    "difficulty": "0x400",
    "gasLimit": "0x8000000",
    "alloc": {
        "d69cc234de15189f0ba998a41421961e89837fc5": {
            "balance": "30000000000000000000000000000"
        }
    }
}

The address specified here needs to be created before initializing the genesis block. You can create the address manually using geth , or you can use the one you created with WalletUtils.generateFullNewWalletFile() . The important part here is to make sure to use the same keystore directory when running your geth commands. Whatever destinationDirectory you passed into generateFullNewWalletFile() needs to be passed into geth with the --keystore option.

If you've already created your private blockchain and allocated ether to a different account than the one you created in web3j, make sure you're using the same keystore directory for both accounts (and the directory matches the --keystore option) and simply transfer the ether from your original account to the new one you created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM