简体   繁体   English

web3j 中凭证的钱包路径是什么?

[英]What is the wallet path for credentials in web3j?

I am using the readme guide https://github.com/web3j/web3j .我正在使用自述指南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.我感兴趣的是从我的主机使用 Java + Web3j 开发智能合约到在我的虚拟机上运行的私有以太坊网络。

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?我应该在我的虚拟机上生成帐户,然后将wallet.json文件复制到我的主机吗?

WalletUtils.loadCredentials can be buggy, I would recommend creating the accounts before hand, and then you can extract the private key and use WalletUtils.loadCredentials 可能有问题,我建议您事先创建帐户,然后您可以提取私钥并使用

Credentials.create(privateKey)

You can use the keystore file and use myetherwallet to view your private key.您可以使用密钥库文件并使用 myetherwallet 来查看您的私钥。

I wouldn't recommend using WalletUtils.loadCredentials() because can be buggy.我不建议使用WalletUtils.loadCredentials()因为可能有问题。

I recommend you:我推荐你:

1. Create the accounts before hand, for example in myetherwallet or with web3j using: web3j wallet create 1.事先创建帐户,例如在myetherwallet中或使用 web3j 使用: web3j wallet create

2. Extract the private key or the password and walletfile. 2.提取私钥或密码和钱包文件。

3. Use Credentials.create() . 3.使用Credentials.create()

Alternative 1:备选方案 1:

If you have the password and the walletfile, you can use:如果你有密码和钱包文件,你可以使用:

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

Alternative 2:备选方案 2:

If you have the EcKeyPair, you can use:如果您有 EcKeyPair,您可以使用:

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

Alternative 3:备选方案 3:

If you have the privateKey, you can use:如果你有 privateKey,你可以使用:

Credentials credentials = Credentials.create(privateKey);
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.像纯文本一样传递私钥可以给你一些奇怪的结果,将他传递到 ECKeyPair 中,然后你就可以访问你的公钥和地址。 i am developing in android with kotlin and i dont have any troubles我正在使用 kotlin 在 android 中开发,我没有任何问题

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钱包路径是保存你的 json 的地方,每次你想得到你的钥匙时,你必须把相同的路径和你的密码

WalletUtils.loadCredentials() method takes password in frist argument and in second argument it takes path of wallet UTC file which you already have created. WalletUtils.loadCredentials() 方法在第一个参数中采用密码,在第二个参数中采用您已经创建的钱包 UTC 文件的路径。 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如果不创建任何钱包,那么您应该首先创建钱包通过 WalletUtils.createWallet() 提供密码和路径,您希望在成功创建钱包后保存 utc 文件,utc 文件将保存在您提供的位置,然后您可以使用 WalletUtils .loadCredentials() 加载凭证并签署交易

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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