Setting up a Starknet account
Installation
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: $[ACCOUNT_ADDRESS_TRIMMED]
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
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 L2 account.
You can acquire L2 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 (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: 822400000000000 WEI (0.000822 ETH).
Gas usage: 8224
Gas price: 100000000000 WEI
You can also run the following command:
|
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.
Using the builtin wallet providers that are part of the |