Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parity.personalNewAccountFromWallet(...) returns NullPointerException with valid arguments #72

Closed
beatrizsanchez opened this issue Mar 19, 2017 · 2 comments
Labels
bug A bug in behaviour or functionality
Milestone

Comments

@beatrizsanchez
Copy link

beatrizsanchez commented Mar 19, 2017

Goal
I am trying to create a wallet on a client that is not running a node and then create a new account on the blockchain from that wallet through parity.personalNewAccountFromWallet(...).

Context
I can't find a way to access the credentials of an account created with parity.personalNewAccount(...) because WalletUtils.loadCredentials(...) will try loading the wallet from the remote client instead of the machine running the node. Therefore, I thought that the best way to create an account would be through the wallet.

What I am doing
I am running personalNewAccountFromWallet(...) with non-null valid arguments (WalletFile and Password) yet the method throws a NullPointerException. My code is as follows:

ECKeyPair ecKeyPair = Keys.createEcKeyPair();
Credentials credentials = Credentials.create(ecKeyPair);
WalletFile wallet = Wallet.createLight(password, ecKeyPair);
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
String output =  walletDir + "/" + wallet.getAddress() + ".json";
objectMapper.writeValue(new File(output), wallet);
parity.personalNewAccountFromWallet(wallet, password).send();

I need to know if this is an implementation error on my side or from the tools (web3j or ethereum)

Whether it was my mistake or not, I think the error message could be more helpful..

@conor10
Copy link
Contributor

conor10 commented Mar 20, 2017

Hi @beatrizsanchez, it appears that the parity API has changed - this call is now named slightly differently from when I originally implemented it, which is why it is failing.

https://github.com/paritytech/parity/wiki/JSONRPC-parity_accounts-module#parity_newaccountfromwallet

You're welcome to submit a PR to rename this.

In terms of your code, the following is a more straight forwards implementation:

String password = "password";
String destDir = "/Users/Conor/tmp";
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();

String walletFileName = WalletUtils.generateNewWalletFile(password, new File(destDir), false);
WalletFile walletFile = objectMapper.readValue(
        new File(destDir + File.separator + walletFileName), WalletFile.class);

NewAccountIdentifier newAccountIdentifier = parity.personalNewAccountFromWallet(
        walletFile, password).send();

I've raised #74 for the main piece of work that needs to be done to support all of the revised calls properly.

@conor10 conor10 added the bug A bug in behaviour or functionality label Aug 9, 2017
@conor10 conor10 added this to the 3.0 milestone Aug 9, 2017
@conor10
Copy link
Contributor

conor10 commented Aug 9, 2017

Fixed by #147.

@conor10 conor10 closed this as completed Aug 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in behaviour or functionality
Projects
None yet
Development

No branches or pull requests

2 participants