Create a Starknet Account in Go | starknet.go Tutorial

Nethermind · 10 Jan 2026 · 9:50

A tutorial on creating and deploying a Starknet account with starknet.go, Nethermind's Go SDK. The presenter works through the documentation example: generating a key pair, precomputing the account address, funding it, building the deploy transaction with fee estimation, and sending it on Sepolia testnet. Along the way it explains why every Starknet account is a smart contract and how an existing OpenZeppelin account class hash is reused. The finished account is confirmed on Voyager. Suitable for Go developers new to Starknet and account abstraction.

Topics

From Nethermind; community: Nethermind.

Transcript

Hey everyone, today I'm going to show you how to deploy a starknet account using starknet go and more importantly I want to show you how the starknet goss have literally everything that you need to build on starknet using golan things like deploying accounts invoking contracts and reading events it's all in here with copy paste examples so let's walk through it together so this is the started go documentation site on the left you have got a sidebar with everything organized very nicely.

We have got an introduction section for getting started and then detailed dogs for each of the modules like account RPC DevNet contracts utils. Today we are deploying a contract account. So let's start with getting started and then jump to the deploy account example. So in getting started, you can see there are some prerequisites and this is how you set up a project. So basically what we have to do is that copy this command spin up a terminal.

Let me clear this and then let us just paste this. What this is doing is that it is creating a folder name app. We are going inside that folder and then initializing our go project. After this has been done, we have to copy this command which is basically adding the dependencies to our project which is startnet go and go.env. Okay. And the next part would be for us to open it in VS code.

Now here I have to create a main.go go file and also create a env file where our environment variables would be stored. Now basically you can see that the environment variable which we need is startnet RPC URL. So let me copy this paste it here and we have to get a RPC URL. I'll be taking that from alchemy. Let me paste that. Then go inside the main go file and copy paste as it is from the example section in the deploy account.

We'll copy this code snippet and paste it inside the file. Now as you can see we might be facing some errors which is from the compiler. Now what we have to do is that run go mod tidy command so that it will install all the related dependencies and then we would not see all these errors inside our code file and as you can see those have been resolved. Let me close this terminal and now what I would do is that explain you through each part of this code and walk you through the whole process of deploying a account on startnet. So as you can see these are some standard

go imports at the top. Then there are some imports like felt from which is coming from Juno here as you can see. Then there is account which is coming from stark net go and RPC also which is coming from stark net go and there is a utils uh packet which is coming from stark net go module as well. Then we also need the env module for us to import the environment variables from the env file. Then we can see that there is a pre-eployed class hash which is this and it is present on sepoleia. Now this is important as on starknet all the

accounts are smart contracts and this hash points to the open zepplint account contract that is already declared on seapia. So we are not deploying a new code. We are creating an instance of this existing contract class hash for our own account. If you look closely, this is a pretty standard setup where we are loading the environment variables, grabbing the RPC URL and creating a context and then initializing the RPC client. The client is our connection to the Stark network. These are some freshly generated cryptographic keys.

the private keys for signing transactions and the public key that identifies our account and basically those are being created using the random keys get random keys function from the account package and we are also printing them here. Now we create an account instance. We pass in the client which uses the public key as a temporary address for now and link it to our key store and specify that we are using cyro v2 since we are using modern cyro contracts. This account object will handle signing and sending our deploy transaction.

Now in the next part you can see that we are converting our class hash string to a felt. That's the format which starknet uses internally. Then we have the build and estimate deploy account transaction. Now what is basically happening is that it is the key function for our explanation. And let me explain the parameters. The pub is basically the salt which randomizes our contract address class hash which contract which is the contract class that we are instantiating.

Then we have the constructor called data. Uh the open sub account takes the public key as its only argument. And then we are using nil because we are not using any special transaction options. Now this function does two things. It builds and deploy transaction and estimates the fee as well. The premputed address is super important on starknet. we can calculate our account address deterministically before it even exists on chain. Then we print the premputed address and save our credentials to the environment variable environment file env file. And this is crucial. You don't

want to lose your private keys. And this is a helper function uh save credentials to environment at the bottom of the file that handles this. You can go through it. It is pretty simple. Now for this section, Starknet uses a resource-based fee model which is rest bounds map to overall fee which calculates the total fee from the resource bounds that were estimated earlier. Then fri to stark converts from fri which is the smallest unit to stark which is easier to read.

The program then pauses and waits for us to fund the precomputed address. This is the key insight about stark net account deployment. You fund an address that doesn't exist yet and then deploy the account contract to that exact same address. Once we have funded, we call send transaction with our deploy transaction. The response gives us the transaction has and confirms the contract address which should match our premputed address. Then we wait for the confirmation using this helper function. As you can see, this was the save credentials to environment uh uh helper function which I created. And then there is a wait for transaction helper function.

So basically this polls the network every 5 seconds checking if a transaction is accepted on L2 or L1. And once it is confirmed we get the receipt with the block number and finality status. Simply polling pattern nothing fancy. So all right uh enough talking. Let's uh try to run this file. Let me open my terminal and we have to run this file core run.co and press enter. So there we go. Our key pair is generated and there's our premputed address. The credentials are saved to environment variables as you can see.

And now we have to fund this address which is present here. with these many stock tokens. We can send a little more than that as well. So it is 0.01. I'll be sending some amount to this address uh 0.03. And let's confirm this transaction. Okay. So our account has been funded and let's press enter to deploy.

The transaction is submitted. Now we have to wait for confirmation. And there it is. The account has been deployed successfully. And let's verify this account on Voyager. If I open Voyager Rapolia, let me paste this. And as you can see, the account has been deployed. So that's it. We went from a zero to a deployed stacket account and the entire code came straight from the docs. So bookmark this

documentation and if you have any questions there's a telegram group which is linked in the sidebar and thanks for watching. Go build something cool on stagnet.

Related talks