var img = document.createElement('img'); img.src = "" + location.pathname; = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

Use Terrain with the testnet

The Pisco testnet is used for testing transactions on the Terra network.


Create a test wallet

Open the Station browser extension and create a new wallet for testing purposes. It is recommended that you name this wallet "Pisco" or "testnet" so that it's easy to remember.

After creating a test wallet and storing the seed phrase, request funds from the testnet faucet in order to have tokens to carry out transactions on testnet.


Make sure you have your seed phrase available as you will need it to complete this tutorial.

Counter tutorial

After creating a test wallet, you are ready to use Terrain. This short tutorial walks you through setting up your project and creating a simple counter that increments upon request.

1. Scaffold your dApp

Scaffold your new application.

terrain new my_terra_dapp
cd my_terra_dapp
npm install

Project structure

Your scaffolded project will have the following structure.

├── contracts # The contracts' source code.
│ ├── my_terra_dapp
│ └── ... # Add more contracts here.
├── frontend # The front-end application.
├── lib # Predefined functions for task and console.
├── tasks # Predefined tasks.
├── keys.terrain.js # Keys for signing transactions.
├── config.terrain.json # Config for connections and contract deployments.
└── refs.terrain.json # Deployed code and contract references.

2. Configure the testnet

Before deploying, you will need to supply your test wallet's mnemonic to Terrain so that it can use the wallet to carry out transactions. To do this, you'll need to modify keys.terrain.js in the generated project.

Modify the configuration and provide your seed phrase.

module.exports = {
pisco: {

3. Deploy

To deploy the application, you can run the following command in your terminal.

terrain deploy my_terra_dapp --signer <your-test-wallet-name> --network testnet

The deploy command performs the following steps automatically.

  • Builds the smart contract.
  • Optimizes the smart contract.
  • Uploads the smart contract to testnet.
  • Instantiates the deployed smart contract.

If you get the following error, wait a few seconds and then try running the deploy command again.

CLIError: account sequence mismatch, expected 1, got 0: incorrect account sequence

3. Generate TypeScript client

Terrain 0.5.x and above includes the ability to automatically generate a TypeScript client based on your smart contract schema.

You can generate a client by running the following command in your terminal.

terrain contract:generateClient my_terra_dapp

The client will be generated in ./lib/clients and copied into the frontend directory.

4. Interact with the deployed contract

The template dApp comes with several predefined helpers in lib/index.js. You can use these to start interacting with your smart contract.

  1. Start the Terrain console.

terrain console --network testnet --signer <your-test-wallet-name>

  1. In the Terrain console, you can increment the counter by running the following command.

await lib.increment();

You can also get the current count.

await lib.getCountQuery();

  1. After incrementing once, await lib.getCountQuery() should return a count of 1.

{ "count": 1 }

5. Front end scaffolding

When you scaffold a template app with Terrain, it will contain a simple front end.

  1. In the Station Chrome extension, switch the network to testnet.

  2. To use the front end, run the following commands.

cd frontend
npm start

  1. With testnet selected in Station you can now increment and reset the counter from the front end.


Advanced usage

For more advanced use cases such as deploying to testnet or mainnet, read Terrain's readme.