Ich versuche, ein Konto mit der web3j-Bibliothek zu erstellen. Aber ich kann die Methode zum Erstellen von Konten nicht finden. Meine Idee ist, dieses Urteil aber nicht in der Geth-Konsole zu treffen, sondern ja in der Java-Anwendung mit web3j:
geth-Konto neu
Irgendeine Idee?
Ich bin neu in Ethereum und bis jetzt erzeuge ich keine Brieftasche, weil ich keine intelligenten Verträge verwende. Meine Idee ist, einfach Konten mit der Java-Anwendung zu erstellen und eine einfache Transaktion von Eth zwischen ihnen in einer privaten Kette durchzuführen.
Danke
Mit Web3j (3.4.0) kann dies in zwei Schritten erreicht werden:
Keys.createEcKeyPair()
Wallet.createStandard(seed, keyPair)
Beispiel:
public static void main(String[] args) {
try {
String password = "secr3t";
ECKeyPair keyPair = Keys.createEcKeyPair();
WalletFile wallet = Wallet.createStandard(password, keyPair);
System.out.println("Priate key: " + keyPair.getPrivateKey().toString(16));
System.out.println("Account: " + wallet.getAddress());
} catch(Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
BEARBEITEN: Erstellen Sie eine Wallet-Datei
String fileName = WalletUtils.generateNewWalletFile(
"secr3t",
new File("/path/to/destination"));
Ich tat dies:
public class MainActivity extends AppCompatActivity {
private WalletFile wallet;
private String password = "PASSWORD";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupBouncyCastle();
try {
wallet = createWallet();
} catch (Exception e) {
System.out.println("BIG RIP");
}
}
public WalletFile createWallet() throws Exception {
ECKeyPair keyPair = Keys.createEcKeyPair();
return Wallet.createLight(password, keyPair);
}
private void setupBouncyCastle() {
final Provider provider = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME);
if (provider == null) {
// Web3j will set up the provider lazily when it's first used.
return;
}
if (provider.getClass().equals(BouncyCastleProvider.class)) {
// BC with same package name, shouldn't happen in real life.
return;
}
// Android registers its own BC provider. As it might be outdated and might not include
// all needed ciphers, we substitute it with a known BC bundled in the app.
// Android's BC has its package rewritten to "com.android.org.bouncycastle" and because
// of that it's possible to have another BC implementation loaded in VM.
Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
Security.insertProviderAt(new BouncyCastleProvider(), 1);
}
}
Aus irgendeinem Grund verursachte das Erstellen einer Brieftasche mit Pfad immer wieder Fehler. Ein Teil meines Codes wurde kopiert von: https://github.com/serso/web3a/blob/4dda74db948f8cbd9a79ba4b9ab456316ea52c4d/app/src/main/java/org/solovyev/android/web3a/App.java#L47 , als neuere Versionen von web3j löst beim Erstellen eines ECKeyPair Fehler aus.
Unerwarteter Charakter
Gregor Jeanmart
Unerwarteter Charakter
Gregor Jeanmart