Setting up an account

This guide shows you how to set up a Starknet account and wallet in the context of a smart contract deployment.

For information on creating a Starknet wallet as an end user, see Getting Started Using Starknet: Setting Up a Starknet Wallet.

Prerequisites

  • Starkli is installed correctly. Ensure that the following command shows the version information for Starkli:

    starkli --version

    If this command fails, see Setting up your environment.

  • A Starknet wallet is installed, either Argent X or Braavos. For information on a specific wallet, including installation instructions, see that wallet’s site.

Creating an account

A smart wallet is composed of two parts:

  • A Signer: A smart contract that can sign transactions.

  • An Account Descriptor: A json file that contains information about the smart wallet, such as its address and public key.

After creating and funding your smart wallet with ETH you can deploy it to Starknet. For demonstration purposes, this page uses Starknet’s testnet.

For testnet transactions you can fund your wallet using one of the Starknet Sepolia faucets.

Creating a Signer

A Signer is a smart contract that can sign transactions. It’s a crucial component of accounts in Starknet. To create a Signer you will need the private key of your smart wallet (the public key can be derived from it).

Starkli has the ability to create a keystore file that securely stores the private key of smart wallets each with a password. The accounts in the keystore file can be used to sign transactions using Starkli. The main advantage of this approach is that it prevents storing the private key as plain text on your computer. Instead, a password is used to create an encrypted file in a location of choice.

Normally, the keystore file is stored in the default location of the Starkli CLI.

Creating a keystore file

The following command creates a keystore file for a smart wallet in the default location in ~/.starkli-wallets/deployer:

Create a new directory:

mkdir -p ~/.starkli-wallets/deployer

Create a keystore file within the directory:

starkli signer keystore from-key ~/.starkli-wallets/deployer/keystore.json

Enter private key:
Enter password:
Created new encrypted keystore file: /home/parallels/.starkli-wallets/deployer/keystore.json
Public key: 0x0550…

In the private key prompt, paste the private key of your smart wallet.

In the password prompt, enter a password of your choice.

You will need this password to sign transactions using Starkli.

Export the private key from your wallet

Next export the private key from your Argent X or Braavos wallet:

Argent X

Navigate to: Settings section → Select your Account → Export Private Key.

Braavos

Navigate to: Settings section → Privacy and SecurityExport Private Key.

While knowing the private key of a smart wallet is necessary to sign transactions, it’s not sufficient. We also need to inform Starkli about the signing mechanism employed by our smart wallet created by Argent X or Braavos.

Creating an Account Descriptor

Starkli offers a command to collect all the required information from a smart wallet by providing its onchain address. Using this data, the CLI generates a json file that can be used to sign transactions:

starkli account fetch --help
Fetch account config from an already deployed account contract

The fetch command supports both Argent X and Braavos smart wallets. Make sure your wallet address is already deployed and enter the following command to create and save the account descriptor file:

starkli account fetch <SMART_WALLET_ADDRESS> --output ~/.starkli-wallets/deployer/account.json --rpc <YOUR_RPC_ENDPOINT_HERE>

You can obtain access to a JSON-RPC endpoint in one of the following ways:

  • Host your own node with Pathfinder, Juno, Deoxys, or Papyrus.

  • Use a third-party JSON-RPC API provider. For information on providers, see Full nodes and API services.

The following command shows the details of the account descriptor:

cat ~/.starkli-wallets/deployer/account.json

The account descriptor should have the following structure:

{
  "version": 1,
  "variant": {
        "type": "argent",
        "version": 1,
        "implementation": "<ARGENT_CLASS_HASH>",
        "signer": "<SMART_WALLET_PUBLIC_KEY>",
        "guardian": "0x0"
  },
    "deployment": {
        "status": "deployed",
        "class_hash": "<SMART_WALLET_CLASS_HASH>",
        "address": "<SMART_WALLET_ADDRESS>"
  }
}

If you are working with Braavos wallet, the type is defined as braavos and the account descriptor structure might be slightly different.

Deploying an account

Once you have an account file, you can deploy the account contract with the starkli account deploy command.

This command sends a DEPLOY_ACCOUNT transaction, which requires the account to contain enough ETH to pay for the transaction fee.

To deploy your account, run the following command:

starkli account deploy ~/.starkli-wallets/deployer/account.json

This command requires a signer. If you receive an error after running this command, ensure you have the STARKNET_KEYSTORE environment variable set as per these instructions.

When run, the command shows:

  • The address where the contract will be deployed.

  • Instructions for the user to fund the account before proceeding.

Here’s an example command output:

The estimated account deployment fee is 0.000011483579723913 ETH. However, to avoid failure, fund at least:
    0.000017225369585869 ETH
to the following address:
    0x01cf4d57ba01109f018dec3ea079a38fc08b789e03de4df937ddb9e8a0ff853a
Press [ENTER] once youve funded the address.

You have now successfully deployed a new account to Starknet.