0

Im trying to create a account using the web3j library. But i can´t find the method that create accounts. My idea is to make this judgment but not in the Geth console, but yes in the Java application using web3j:

geth account new

Any idea?

Im new in ethereum and till the moment im not generating wallet because im not using smart contracts. Mi idea is just create accounts with de Java application and make simple transacion of eth betwen them in a private chain.

Thank you

1

Using Web3j (3.4.0), this can be achieved in two steps:

  1. Generate a key-pair Keys.createEcKeyPair()
  2. Create the wallet Wallet.createStandard(seed, keyPair)

Example:

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());
    }

}

EDIT: create a wallet file

String fileName = WalletUtils.generateNewWalletFile(
        "secr3t",
        new File("/path/to/destination"));
  • Im going to test. but one theorycal question. If in this moment im not going to use smart contrarts its necesarry wallets?? Thk !! – Eduardo Nov 15 '18 at 9:24
  • If you want to send transactions (to an account or a smart contract), you need a funded wallet. Otherwise for events listening or smart contract calls for instance, you don't need a wallet – Greg Jeanmart Nov 15 '18 at 9:35
  • oquei its work and I can se the output. But the wallet creation is not commited/confirmed and it not appear in keystore folder. I need just one line to confirm the previous wallet. What can I do?? – Eduardo Nov 15 '18 at 9:58
  • Just edited my answer with how to generate a Wallet file that can be copied the keystore folder. – Greg Jeanmart Nov 15 '18 at 10:20
  • Thank you so much. Its working nice !!!! ;D – Eduardo Nov 15 '18 at 12:37

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.