如何在ethereumj中创建等效的外部帐户( personal.newAccount())?我知道我可以使用jsonrpc api来这么做吗?但是我读过https://github.com/ethereum/ethereumj/issues/335,它说它可以创建一个帐户,但是它不能,它只是生成地址,但是不包括/添加到密钥存储库中。如何将其添加到密钥存储库中。
发布于 2016-05-24 19:08:44
首先,您需要以下Maven pom.xml依赖项:
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj-core</artifactId>
<version>1.2.0-RELEASE</version>
<!-- <type>zip</type> -->
</dependency>下面是创建私钥/帐户对的代码:
import org.ethereum.crypto.ECKey;
import org.spongycastle.util.encoders.Hex;
public class CreateAccount {
public static void main(String[] args) {
ECKey key = new ECKey();
byte[] addr = key.getAddress();
byte[] priv = key.getPrivKeyBytes();
String addrBase16 = Hex.toHexString(addr);
String privBase16 = Hex.toHexString(priv);
System.out.println("Address : " + addrBase16);
System.out.println("Private Key : " + privBase16);
}
}两次运行代码将产生以下输出:
Address : 82d4b1c01afaf7f25bb21fd0b4b4c4a7eb7120ce
Private Key : 133965f412d1362645cbd963619023585abc8765c7372ed238374acb884b2b3a
Address : 68ccabefc7f4ae21ce0df1d98e50e099d7fc290f
Private Key : 1caeb7f26cb9f3cc7d9d0dbcdd3cf3cb056dbc011ec9013e8f3b8cdb2f193b32使用https://www.myetherwallet.com/#view-wallet-info验证信息:


请注意,在EthereumJ中创建的帐户都是小写的,而使用MyEtherWallet的私钥生成的帐户则是混合大小写。这是因为MyEtherWallet正在使用新的校验和帐户。见又一个很酷的校验和地址编码#55。
https://ethereum.stackexchange.com/questions/4264
复制相似问题