'What is the wallet path for credentials in web3j?
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?
Solution 1:[1]
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.
Solution 2:[2]
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);
Solution 3:[3]
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
Solution 4:[4]
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
Solution 5:[5]
The library you're using listens to the DOMContentLoaded event, so it will load the widgets when the page loads. You can "force" it to reload by dispatching a DOMContentLoaded event on the window, just keep in mind that if you have anything that listens for that event it will trigger too.
leagueSelector.addEventListener('click', function(e) {
// Your code...
window.dispatchEvent(new Event('DOMContentLoaded'));
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | thesivar |
| Solution 2 | |
| Solution 3 | cubo1123 |
| Solution 4 | Arvind Rajput |
| Solution 5 | yainspan |
