Beginner’s Guide To Stacks Testnet Deployment

Ayush Sahu
4 min readDec 24, 2021

This article will be a step by step guide for you to deploy your first smart contract on the stacks testnet.

What is the testnet?

The stacks testnet is a separate blockchain from the stacks mainnet, built for the purpose of testing smart contracts before deployment. That’s all you need to know right now, but if you wanna learn more, the official docs are always a good place to start.

Why deploy to the testnet?

Because deploying to the mainnet costs stacks tokens, thus there’s not much of a space to mess up. Therefore it’s advisable to not deploy to the mainnet until you make absolutely sure that your code works as intended. And you can do this by deploying to the testnet, which is essentially free, and nicely simulates the stacks mainnet.

Alright, let’s get into it. We will start by building a basic smart contract.

These are the prerequisites for writing clarity smart contracts -

  1. Get a code editor.
  2. Install Clarinet.
  3. Install Clarity-repl.

The last one is more of a convenience than a prerequisite, and will be helpful in testing syntax and such.

We’ll write a generic hello-world smart contract, keeping in line with the tradition.

Fire up your terminal, or windows powershell if you’re a normie, and follow along.

At this point you have a clarity project set up, and all that remains between you and your first smart contract is a few lines of code.

Open the hello-world directory in Visual Studio Code, install the Clarity language extension. Now open the file hello-world.clar and paste the following code.

Type it yourself fellas, it’s for your own good :P

This contract does a little more than just saying hello world, it charges you a thousand microstacks for it. Wouldn’t be much of a contract if we didn’t involve money, now would it?

We can call the public function we just wrote inside the clarinet console in our terminal, which by the way you can open inside your vs code.

What are all these terms? Why are there long strings of letters and numbers? Why are they in a box? What’s the last line do? Why is hello-world inside an (ok)?

You’ll learn all of it when you start learning clarity. What the last line does, is it calls functions defined in the contract. The syntax is —

(contract-call? <contract-identifier> function-name)

You can see the contract-identifier in the top grid. That’s about all you need to know right now.

With the contract in place, we can get to deployment. All you need for this is a Hiro wallet. You can make one here.

Now let’s go to the Stacks Sandbox, which is basically a place to test out your smart contracts — https://explorer.stacks.co/sandbox/deploy?chain=testnet. You will get a prompt to login using your Hiro wallet, do that.

After this, go the faucet logo (the fourth one, or the first if you’re hanging like a bat for some reason) and hit Request Stx. You’ll be topped up soon. Just like the mainnet, you need stx tokens to deploy contracts on the testnet too. However these tokens are valueless (but also invaluable, since they allow testing), so don’t get too excited.

Now simply copy your code into the black-code-area-thing. Name your contract, and hit Deploy.

Boom, there’s your first testnet deployment. Congratulations, you have some clarity about deployment now.

You can also call your function to see if it works. See if you can figure out how to. Hint: It’s not hard.

Alright, that concludes this article. Hope it added some value.

Till next time.

--

--