Estoy tratando de crear una cuenta usando la biblioteca web3j. Pero no puedo encontrar el método que crea cuentas. Mi idea es hacer este juicio pero no en la consola Geth, pero si en la aplicación Java usando web3j:
cuenta geth nueva
¿Alguna idea?
Soy nuevo en ethereum y hasta el momento no estoy generando billetera porque no estoy usando contratos inteligentes. Mi idea es simplemente crear cuentas con la aplicación Java y hacer transacciones simples de eth entre ellos en una cadena privada.
Gracias
Usando Web3j (3.4.0), esto se puede lograr en dos pasos:
Keys.createEcKeyPair()
Wallet.createStandard(seed, keyPair)
Ejemplo:
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());
}
}
EDITAR: crear un archivo de billetera
String fileName = WalletUtils.generateNewWalletFile(
"secr3t",
new File("/path/to/destination"));
Hice esto:
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);
}
}
Por alguna razón, la creación de una billetera con ruta seguía arrojando errores. Parte de mi código fue copiado de: https://github.com/serso/web3a/blob/4dda74db948f8cbd9a79ba4b9ab456316ea52c4d/app/src/main/java/org/solovyev/android/web3a/App.java#L47 , como versiones más nuevas de web3j arroja errores al crear un ECKeyPair.
Personaje inesperado
greg jeanmart
Personaje inesperado
greg jeanmart