Setting up a Starknet account and wallet for smart contract deployment
Blockchain technology continues to evolve, and one of the most exciting developments in the Ethereum ecosystem is Starknet, a Layer 2 (L2) solution that offers scalability and cost-efficiency for decentralized applications (dApps). In this guide, we’ll walk you through the process of setting up a Starknet account and wallet in the context of deploying a smart contract. This guide assumes you have Starkli and Scarb correctly installed. If not, refer to our guide on setting up your environment.
Prerequisites. Before you dive into the process, ensure you have the following prerequisites in place:
- Starkli and Scarb installation: Confirm that Starkli and Scarb are installed correctly by running the following commands:
starkli --version
scarb --version
If either of these commands fails, refer to our guide on setting up your environment to resolve the issue.
- Argent X or Braavos wallet: You’ll need a Starknet wallet, which can be obtained via Argent X or Braavos. For specific wallet information and installation instructions, visit the respective wallet’s website.
Creating an account. A Starknet smart wallet consists of two essential components: a Signer and an Account Descriptor. Here’s how to create these components and deploy your smart wallet to Starknet:
1. Creating a Signer. A Signer is a crucial component of Starknet accounts. It’s a smart contract capable of signing transactions. To create a Signer, you’ll need the private key of your smart wallet. Starkli can help you securely store this private key in a keystore file. This approach prevents storing the private key in plain text on your computer, using a password to encrypt it.
First, create a new directory and then the keystore file for your smart wallet:
mkdir ~/.starkli-wallets/deployer
starkli signer keystore from-key ~/.starkli-wallets/deployer/keystore.json
You will be prompted to enter your private key and a password of your choice. This password will be required to sign transactions using Starkli.
2. Exporting the Private key. While knowing the private key is necessary for signing transactions, you also need to inform Starkli about the signing mechanism used by your smart wallet created by Argent X or Braavos.
To do this, export the private key from your wallet:
- For Argent X: Navigate to the Settings section, select your Account, and choose “Export Private Key.”
- For Braavos: Navigate to the Settings section, go to Privacy and Security, and select “Export Private Key.”
3. Creating an account descriptor. Starkli offers a command to collect all the required information from your smart wallet using its onchain address. With this data, the CLI generates a JSON file that can be used to sign transactions:
starkli account fetch <SMART_WALLET_ADDRESS> --output ~/.starkli-wallets/deployer/account.json
You can view the account descriptor’s details using:
cat ~/.starkli-wallets/deployer/account.json
The account descriptor contains essential information about your smart wallet, such as its address and public key.
4. Deploying an account. Once you have an account file, you can deploy your account contract with the starkli account deploy
command. This command sends a DEPLOY_ACCOUNT
transaction, which requires the account to be funded with some ETH for covering the transaction fee.
To deploy your account, use the following command:
starkli account deploy ~/.starkli-wallets/deployer/account.json
If you encounter an error after running this command, ensure that you’ve set the STARKNET_KEYSTORE
environment variable as per the provided instructions.
After running the deployment command, you will receive the address where the contract will be deployed, along with instructions for funding the account. Ensure you fund your account accordingly to complete the deployment process.
Getting started using Starknet: setting up a Starknet wallet:
Congratulations! You have now successfully deployed a new account to Starknet. This paves the way for you to interact with smart contracts and participate in the exciting world of decentralized applications on the Ethereum ecosystem with Starknet’s scalability and cost-efficiency benefits. Happy developing!