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

getAccountFromAddress not working if account not deployed #281

Open
FabijanC opened this issue Dec 16, 2022 · 2 comments
Open

getAccountFromAddress not working if account not deployed #281

FabijanC opened this issue Dec 16, 2022 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@FabijanC
Copy link
Collaborator

FabijanC commented Dec 16, 2022

When doing

starknet.OpenZeppelinAccount.getAccountFromAddress(address, privateKey);

the plugin performs an internal validation that the provided private key matches the deployed public key.
Source code: OpenZeppelinAccount, ArgentAccount

Since starknet-hardhat-plugin v0.7.0, it is a problem if the account contract hasn't yet been deployed (so there is no public key deployed to check against). When can this happen? Assume the following use-case:

const account = await starknet.OpenZeppelinAccount.createAccount(...);
console.log("Account address:", account.address);
// you exit the script to fund the account

Then a new script is run which first tries to get the account:

const account = await starknet.OpenZeppelinAccount.getAccountFromAddress(...);
// FAILS with reporting an UNINITIALIZED_CONTRACT

Originally reported on Discord.

@FabijanC FabijanC self-assigned this Dec 16, 2022
@FabijanC
Copy link
Collaborator Author

FabijanC commented Dec 16, 2022

Currently there are two approaches to solving this:

1. Creating and deploying in the same script

You need to wait between these two steps. This can be achieved in a few ways:

  1. sleep
  2. wait for keypress
const account = await starknet.OpenZeppelinAccount.createAccount(...);
await yourSelectedWayOfWaiting(); // fund during this step
await account.deployAccount(...);

2. Creating and deploying in separate executions

For this to work, you need to use the same private key and the same salt, e.g. via env vars (accessible with process.env).

First create the account to log the address:

const account = await starknet.OpenZeppelinAccount.createAccount({
  salt: process.env.SALT,
  privateKey: process.env.PRIVATE_KEY
});
console.log("Account address:", account.address);

If your script successfully exited, after funding the address you can recreate the same account again:

const account = await starknet.OpenZeppelinAccount.createAccount({
  // the same input data as in the last execution
});
await account.deployAccount(...);

@FabijanC
Copy link
Collaborator Author

FabijanC commented Dec 16, 2022

The question remains how we want to treat this long-term:

  1. Keep the above described method as the recommended way.
  2. Introduce an input parameter to getAccountFromAddress indicating whether the account being retrieved is deployed or not.
  3. Remove the private-public key validation completely.
  4. Introduce an input parameter to createAccount indicating whether to wait for funding or not (adding the keypress solution under the hood).

Personally, I'm leaning towards option 4.

@FabijanC FabijanC added the question Further information is requested label Dec 16, 2022
@ivpavici ivpavici moved this from 🆕 New to 📋 Backlog in starknet-hardhat-plugin Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant