3

我正在使用自述指南https://github.com/web3j/web3j

我感兴趣的是使用 Java + Web3j 从我的主机开发智能合约到在我的虚拟机上运行的私有以太坊网络。

有这样的行:

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

所以问题是:

我应该如何创建这个钱包?我应该在我的虚拟机上生成帐户,然后将wallet.json文件复制到我的主机吗?

4

4 回答 4

2

WalletUtils.loadCredentials 可能有问题,我建议您事先创建帐户,然后您可以提取私钥并使用

Credentials.create(privateKey)

您可以使用密钥库文件并使用 myetherwallet 来查看您的私钥。

于 2017-12-07T19:48:32.443 回答
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);
于 2018-09-24T07:06:48.010 回答
1
val k = ECKeyPair.create(BigInteger(credentialsOne.ecKeyPair.privateKey.toString()))
            val test = Credentials.create(k)

像纯文本一样传递私钥可以给你一些奇怪的结果,将他传递到 ECKeyPair 中,然后你就可以访问你的公钥和地址。我正在使用 kotlin 在 android 中开发,我没有任何问题

钱包路径是保存你的 json 的地方,每次你想得到你的钥匙时,你必须把相同的路径和你的密码

于 2018-02-07T14:51:50.930 回答
0

WalletUtils.loadCredentials() 方法在第一个参数中采用密码,在第二个参数中采用您已经创建的钱包 UTC 文件的路径。如果不创建任何钱包,那么您应该首先创建钱包 通过 WalletUtils.createWallet() 提供密码和路径,您希望在成功创建钱包后保存 utc 文件,utc 文件将保存在您提供的位置,然后您可以使用 WalletUtils .loadCredentials() 加载凭证并签署交易

于 2018-07-13T04:33:41.007 回答