3

I am using the readme guide https://github.com/web3j/web3j.

What I am interested is developing smart contracts from my host with Java + Web3j to private Ethereum network which runs on my virtual machine.

There are such lines:

Web3j web3 = Web3j.build(new HttpService());  // defaults to http://localhost:8545/
Credentials credentials = WalletUtils.loadCredentials("password", "/path/to/walletfile");

How should I create this wallet? Should I generate account on my VM and then copy wallet.json file to my host?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Anna
  • 53
  • 1
  • 6

4 Answers4

3

I wouldn't recommend using WalletUtils.loadCredentials() because can be buggy.

I recommend you:

1. Create the accounts before hand, for example in myetherwallet or with web3j using: web3j wallet create

2. Extract the private key or the password and walletfile.

3. Use Credentials.create().

Alternative 1:

If you have the password and the walletfile, you can use:

Credentials credentials = Credentials.create(Wallet.decrypt(password, walletFile));

Alternative 2:

If you have the EcKeyPair, you can use:

Credentials credentials = Credentials.create(getEcKeyPair());

Alternative 3:

If you have the privateKey, you can use:

Credentials credentials = Credentials.create(privateKey);
Javier C.
  • 7,859
  • 5
  • 41
  • 53
2

WalletUtils.loadCredentials can be buggy, I would recommend creating the accounts before hand, and then you can extract the private key and use

Credentials.create(privateKey)

You can use the keystore file and use myetherwallet to view your private key.

thesivar
  • 23
  • 6
1
val k = ECKeyPair.create(BigInteger(credentialsOne.ecKeyPair.privateKey.toString()))
            val test = Credentials.create(k)

pass the private key like plain text can give you some stranger results, pass him inside an ECKeyPair and then you will have acces to your public key and address. i am developing in android with kotlin and i dont have any troubles

the wallet path is the place where your json will be saved, and every time you wanna get your keys you has to put the same path and your passphrase

cubo1123
  • 151
  • 1
  • 4
0

WalletUtils.loadCredentials() method takes password in frist argument and in second argument it takes path of wallet UTC file which you already have created. If don't create any wallet then you should frist create wallet By WalletUtils.createWallet() provide password and path where you want to save utc file after successfully creation of wallet a utc file will be save on your provided location then you can use WalletUtils.loadCredentials() to load the credentials and sign transaction