Setting up a StarkNet account


Follow the installation instructions for the cairo-lang package in Setting up the environment.

Setting up the network

In this tutorial we will use the StarkNet CLI (command line interface) to interact with StarkNet. In order to instruct the CLI to work with the StarkNet testnet you may either add the --network=alpha-goerli flag to every command, or simply set the STARKNET_NETWORK environment variable as follows:

export STARKNET_NETWORK=alpha-goerli

Choosing a wallet provider

Unlike Ethereum, which distinguishes between Externally Owned Accounts (EOA) and contracts, StarkNet doesn’t have this distinction. Instead, an account is represented by a deployed contract that defines the account’s logic – most notably the signature scheme that controls who can issue transactions from it.

To interact with StarkNet, you will need to deploy an account contract. In this tutorial, we will use a slightly modified version of OpenZeppelin’s standard for EOA contract (at the moment, the signature is computed differently). Set the STARKNET_WALLET environment variable as follows:

export STARKNET_WALLET=starkware.starknet.wallets.open_zeppelin.OpenZeppelinAccount

Creating an account

Run the following command to initialize an account:

starknet new_account

The output should resemble:

Account address: 0x78d796e87cfa496bffad27be9ed42f2709bd6e32a6366f842fdf38664a1412d
Public key: ...
Move the appropriate amount of funds to the account, and then deploy the account
by invoking the 'starknet deploy_account' command.

NOTE: This is a modified version of the OpenZeppelin account contract. The signature is computed

Transferring Goerli ETH to the account

In order to pay the fees required to deploy the account and execute transactions on StarkNet, you need enough ETH in your L2 account.

You can acquire L2 ETH in the following ways:

  1. Use the StarkNet Faucet to get small amounts of ETH directly to the account you have just created. This should suffice for simple transactions.

  2. Use StarkGate – the StarkNet L2 bridge (L1 contract / Web App) to transfer your existing Goerli L1 ETH to and from the L2 account.

To estimate the fee required to deploy the account, run the following command:

starknet deploy_account --simulate

Find the following lines in the output:

The estimated fee is: 766200000000000 WEI (0.000766 ETH).
Gas usage: 7662
Gas price: 100000000000 WEI

Note: you can also run the following command:

starknet deploy_account --estimate_fee

Deploying an account

To deploy the account you initialized, run the following command:

starknet deploy_account

The output should resemble:

Sent deploy account contract transaction.

Contract address: ...
Transaction hash: ...

You may also specify a name for your account using --account=my_account if you want to maintain multiple accounts. If not specified, the default account (named __default__) is used.

The STARKNET_WALLET environment variable instructs the StarkNet CLI to use your account in the starknet invoke and starknet call commands. If you want to do a direct call to a contract, without passing through your account contract, you can pass the --no_wallet argument to the CLI, which overrides the STARKNET_WALLET variable.

Warning: Using the builtin wallet providers that are part of the cairo-lang package (starkware.starknet.wallets...) is not secure (for example, the private key may be kept unencrypted and without backup in your home directory). You should only use them if you’re not overly concerned with losing access to your accounts (for example, for testing purposes). In addition, they are not deployed using the proxy pattern, so they cannot be upgraded and may stop working in future versions of StarkNet.