Setting up a Starknet account
Introduction
Before you create a Starknet account, ensure you have completed the steps in the environment setup section of these docs. |
In order to interact with Starknet, you need to set up a Starknet account. To deploy a new account on Starknet you will need to complete the following steps:
-
Generate a Starknet account and compute its address locally
-
Fund your account so that you can deploy the account to the Starknet network
-
Deploy the account to the Starknet network
Starknet natively uses Account Abstraction at the protocol layer for account implementation. You can learn more about Starknet Account Abstraction here.
Setting up the network
In this tutorial we will use the Starknet CLI (command line interface) to interact with Starknet.
Setting the following environment variables will allow you to use the Starknet CLI to interact with a consistent set of configurations without having to pass them as arguments to each command:
export STARKNET_NETWORK=alpha-goerli
export CAIRO_COMPILER_DIR=~/.cairo/target/release/
export CAIRO_COMPILER_ARGS=--add-pythonic-hints
Choosing a wallet provider
Unlike Ethereum, a Starknet account is represented by a deployed contract that defines the account’s logic. 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
Now that your environment variables are set, you can create a Starknet account.
Run the following command to initialize an account:
starknet new_account --account <account_name>
The output should resemble:
Account address: 0x04e93e1fb507d23b398f0a09f5873d3a7769b0e7ed40dbbe8fe7a2e8ea831006
Public key: 0x07a328511fa8552cd61aaaa89076fe40c3566f4594f29324aa754d41d7c7c55e
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
differently.
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 Starknet account.
You can acquire Starknet Goerli ETH in the following ways:
-
Use the Starknet Faucet to get small amounts of ETH directly to the account you have just created. This should suffice for simple transactions.
-
Use StarkGate – the Starknet L2 bridge, to transfer your existing Goerli L1 ETH to and from your Starknet account.
In either case, ensure that the funding transaction reaches the "PENDING" status on Starknet before proceeding.
Simulate deploy account
You can estimate the fee required to deploy your account by running the following command.
To account for fluctuations in fee prices, it is recommended to transfer more than the fee estimation value to ensure that your transaction is successful.
starknet deploy_account --simulate --account=<account_name>
The output should resemble:
The estimated fee is: 822400000000000 WEI (0.000822 ETH).
Gas usage: 8224
Gas price: 100000000000 WEI
Alternatively you can run the following command for a less verbose output:
|
Deploying an account
To deploy the account you initialized, now run the following command:
starknet deploy_account --account=<account_name>
The output should resemble:
Sending the transaction with max_fee: 0.000563 ETH (562652117844076 WEI).
Sent deploy account contract transaction.
Contract address: 0x04e93e1fb507d23b398f0a09f5873d3a7769b0e7ed40dbbe8fe7a2e8ea811006
Transaction hash: 0x69192a77c527fb10a71722400dbad15bdb3a8db237db4f72e06f3b4b63f2195
You have now successfully deployed a new account to Starknet.