Creating And Deploying Accounts

Account is required to perform interactions with Starknet (only calls can be done without it). Starknet Foundry sncast supports entire account management flow with the sncast account create and sncast account deploy commands.

Difference between those two commands is that the first one creates account information (private key, address and more) and the second one deploys it to the network. After deployment, account can be used to interact with Starknet.

To remove an account from the accounts file, you can use sncast account delete. Please note this only removes the account information stored locally - this will not remove the account from Starknet.

💡 Info Accounts creation and deployment is supported for

  • OpenZeppelin
  • Argent (with guardian set to 0)
  • Braavos

Examples

Creating an Account

Do the following to start interacting with the Starknet:

Create account with the sncast account create command

$ sncast \
    account create \
    --url http://127.0.0.1:5055 \
    --name new_account
Output:
command: account create
add_profile: --add-profile flag was not set. No profile added to snfoundry.toml
address: [..]
max_fee: [..]
message: Account successfully created. Prefund generated address with at least <max_fee> STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand.

To see account creation details, visit:
account: https://sepolia.starkscan.co/contract/[..]

For a detailed CLI description, see account create command reference.

See more advanced use cases below or jump directly to the section here.

Prefund generated address with tokens

To deploy an account in the next step, you need to prefund it with either STRK or an equivalent amount of ETH tokens (read more about them here). You can do it both by sending tokens from another starknet account or by bridging them with StarkGate.

💡 Info When deploying on a Sepolia test network, you can also fund your account with artificial tokens via the Starknet Faucet image

Deploy account with the sncast account deploy command

$ sncast \
    account deploy \
    --url http://127.0.0.1:5055 \
	--name new_account \
	--max-fee 9999999999999
Output:
command: account deploy
transaction_hash: [..]

To see invocation details, visit:
transaction: https://sepolia.starkscan.co/tx/[..]

For a detailed CLI description, see account deploy command reference.

Managing Accounts

If you created an account with sncast account create it by default it will be saved in ~/.starknet_accounts/starknet_open_zeppelin_accounts.json file which we call default accounts file in the following sections.

account import

To import an account to the default accounts file, use the account import command.

$ sncast \
    account import \
	--url http://127.0.0.1:5055 \
    --name my_imported_account \
    --address 0x3a0bcb72428d8056cc7c2bbe5168ddfc844db2737dda3b4c67ff057691177e1 \
    --private-key 0x2 \
    --type oz

account list

List all accounts saved in accounts file, grouped based on the networks they are defined on.

$ sncast account list
Output:
Available accounts (at [..]):
- new_account:
  network: alpha-sepolia
  public key: [..]
  address: [..]
  salt: [..]
  class hash: [..]
  deployed: false
  legacy: false
  type: OpenZeppelin

- my_account:
  network: alpha-sepolia
  public key: 0x48234b9bc6c1e749f4b908d310d8c53dae6564110b05ccf79016dca8ce7dfac
  address: 0x6f4621e7ad43707b3f69f9df49425c3d94fdc5ab2e444bfa0e7e4edeff7992d
  deployed: true
  type: OpenZeppelin

You can specify a custom location for the accounts file with the --accounts-file or -f flag. There is also possibility to show private keys with the --display-private-keys or -p flag.

account delete

Delete an account from accounts-file and its associated Scarb profile. If you pass this command, you will be asked to confirm the deletion.

$ sncast account delete \
    --name new_account \
    --network alpha-sepolia

Advanced Use Cases

Custom Account Contract

By default, sncast creates/deploys an account using OpenZeppelin's account contract class hash. It is possible to create an account using custom openzeppelin, argent or braavos contract declared to starknet. This can be achieved with --class-hash flag:

$ sncast \
    account create \
    --name new_account_2 \
    --url http://127.0.0.1:5055 \
    --class-hash 0x00e2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6
    --type oz

account create With Salt Argument

Instead of random generation, salt can be specified with --salt.

$ sncast \
    account create \
    --url http://127.0.0.1:5055 \
    --name another_account_3 \
    --salt 0x1

Additional features provided with account import/create

Specifying --accounts-file

Account information such as private_key, class_hash, address etc. will be saved to the file specified by --accounts-file argument, if not provided, the default accounts file will be used.

Specifying --add-profile

When the --add-profile flag is used, you won't need to include the --url or --accounts-file parameters (the latter being necessary if your account information was stored in a custom file). Simply use the --profile argument followed by the account name in subsequent requests.

Using Keystore and Starkli Account

Accounts created and deployed with starkli can be used by specifying the --keystore argument.

💡 Info When passing the --keystore argument, --account argument must be a path to the starkli account JSON file.

$ sncast \
    --keystore keystore.json \
    --account account.json  \
    declare \
	--url http://127.0.0.1:5055 \
    --contract-name my_contract \

Creating an Account With Starkli-Style Keystore

It is possible to create an openzeppelin account with keystore in a similar way starkli does.

$ sncast \
    --keystore my_key.json \
    --account my_account.json \
    account create \
    --url http://127.0.0.1:5050 

The command above will generate a keystore file containing the private key, as well as an account file containing the openzeppelin account info that can later be used with starkli.