Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE
Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE
Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE
Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE
Need a crash course on Bitcoin layers?
→ READ OUR FREE GUIDE

5 Ways to Interact With Devnet in the Hiro Platform

Devnet is a local blockchain environment that lets you test and validate your contract code before deploying on a public network like testnet or mainnet. In this blog, we’ll show you how to take advantage of all devnet has to offer in the Hiro Platform.

Type
Tutorial
Topic(s)
Hiro
Product
Published
May 15, 2024
Author(s)
Sr. Product Marketing Manager
Sr. Software Engineer
A collage of various devnet features
Contents

You can think of devnet as your own personal blockchain sandbox—no one else can see it, you don’t have to worry about breaking it, and you can stop and restart it as many times as you need. It comes with blockchain nodes and miners and will produce blocks on your local machine.

Devnet offers rapid prototyping and quick feedback loops through its customizable testing environment.

We first launched devnet in the Hiro Platform last fall, and now we’ve revamped the UI in the platform to give you an even better experience. Let’s talk about what’s new once you click the "Start Devnet" button.

Meet the Devnet Dashboard

Once you’ve started devnet in the Hiro Platform, you can toggle to “View Devnet Activity”, which will take you to the devnet dashboard, a lightweight explorer view where you can view mined blocks and their transactions.

You can also customize your devnet instance by opening your project’s devnet.toml file in the platform VS Code editor and configuring your settings to match your deployment needs.

From this dashboard, you can also find 5 different ways to interact with devnet:

Call Contract Functions

One of the first ways to see if a contract is working as expected is to call functions in the contract. But in order to call a function in a smart contract, the contract has to be deployed on a blockchain environment first.

And maybe you don’t want to deploy your unfinished prototype on a public network. Once you deploy on a public network, you can’t update/change the code, and if you’re early in development, you will likely need to iterate a lot on it. The workaround is to rename your contract each time you redeploy to the public network, but tracking all of those name changes can be a nightmare.

It’s much easier to simply use devnet, which enables you to tear it all down and spin it up again at will, so you can easily make changes to your code.

When you start devnet in the Hiro Platform, you deploy your contracts on that network, and you can then call public and read-only functions in your contract. 

Note that when you call read-only functions, you’re simply fetching or reading data from the blockchain.

With public functions, you can change data on the blockchain. When you call public functions, you create a transaction, and that transaction comes with accompanying transaction fees that need to be paid for in order for the transaction to be executed and confirmed (even in this private devnet instance—it is a blockchain after all).

With devnet, you can call a function and pay for the transaction fee using one of devnet’s pre-funded wallets. Speaking of…

Pay Devnet Transaction Fees With Pre-Loaded Wallets

Every devnet instance automatically comes with a set of STX addresses pre-loaded with devnet tokens. This enables you to easily test out different scenarios related to your contracts, such as calling public functions (which requires paying for transaction fees) or testing contract functionality (which might include sending and receiving value between addresses).

Integrate Contracts With Your App Using an API URL

When you click, “Interact with Devnet”, one option you have is to “View URL”. This Stacks API URL can be used to connect to your devnet programmatically. When you're developing an app, it’s helpful to see how your contracts work within your application frontend.

In order to do that, you’ll want to integrate your contracts with your dapp using an API URL. With the Hiro Platform, you get a dedicated URL for your devnet instance to plug into your app code. This URL lets your dapp make calls and transactions against your devnet instance.

Make API Requests

You can also make API requests directly in the Hiro Platform to your devnet’s instance of the Stacks Blockchain API. This enables you to send data requests to devnet and view the responses directly in the Hiro Platform.

This is a useful way to try out API endpoints and inspect their outputs to get a feel for what pieces of info you’d have available in your application code.

Open in Stacks Explorer

You can also choose to open your devnet instance in the Stacks Explorer. This allows you to access a view you are already familiar with and one that provides more detailed information, such as the contract code for deployments, tx caller addresses, nonce, fees, memo, and more.

Conclusion

We know Web3 development can seem daunting, but with the right tools, anyone can get started. If you want to see these devnet features in action, watch Hiro’s software engineer Leah dive into the process of writing and testing a Stacks smart contract all within the Hiro Platform:

Now that you've discovered the powers of devnet, are you ready to try devnet out for yourself in the Hiro Platform?

Product updates & dev resources straight to your inbox
Your Email is in an invalid format
Checkbox is required.
Thanks for
subscribing.
Oops! Something went wrong while submitting the form.
Go to Platform
Copy link
Mailbox
Hiro news & product updates straight to your inbox
Only relevant communications. We promise we won’t spam.

Related stories