Terra development environment for better smart contract development experience.

Related tags

Maps terrain
Overview

Terrain

terrain logo

Terrain – Terra development environment for better smart contract development experience


Terrain will help you:

  • scaffold your dapp project
  • ease the development and deployment process
  • create custom task for blockchain and contract interaction with less boilerplate code
    • using terra.js directly could be cumbersome, Terrain gives you extensions and utilities to help you
  • console to terra blockchain, an interactive repl which have the same extensions and utilities as custom task
  • ability to predefine functions to be used in task and console

oclif Version Downloads/week

Setup

Download LocalTerra

For local developement environment, you need LocalTerra.

note: if you are using m1 chip, you might need to update your Docker Desktop due to qemu bug

git clone --branch v0.5.17 --depth 1 https://github.com/terra-money/localterra
cd localterra
docker-compose up

Setup Rust

While WASM smart contracts can theoretically be written in any programming language, we currently only recommend using Rust as it is the only language for which mature libraries and tooling exist for CosmWasm. For this tutorial, you'll need to also install the latest version of Rust by following the instructions here.

Then run the following commands

set stable as default release channel (used when updating rust)

rustup default stable

add wasm as compilation target

rustup target add wasm32-unknown-unknown

for generating contracts

cargo install cargo-generate --features vendored-openssl
cargo install cargo-run-script

Setup Node

To run Terrain you need to install Node.js and NPM. We recommend the Node.js LTS 16 and Node Package Manager (NPM) 8.5.0 which is the default installed version for Node.js LTS 16.

If you encounter the next error code: error:0308010C:digital envelope routines::unsupported use LTS Node.js 16.

Getting Started

Assumed that you have setup the node env, let's generate our first app

For the first time, you will need to run npm install -g @terra-money/terrain or npx @terra-money/terrain new my-terra-dapp since terrain npm module name is occupied by another module.

npx terrain new my-terra-dapp
cd my-terra-dapp
npm install

Project Structure

The project structure will look like this:

.
├── contracts              # contracts' source code
│   ├── counter
│   └── ...                # more contract can be added here
├── frontend               # frontend application
├── lib                    # predefined functions for task and console
├── tasks                  # predefined tasks
├── keys.terrain.js        # keys for signing transacitons
├── config.terrain.json    # config for connections and contract deployments
└── refs.terrain.json      # deployed code and contract referecnes

You will now have counter example contract (no pun intended).

Deployment

We can right away deploy the contract on LocalTerra. Not specifying network will be defaulted to localterra.

npx terrain deploy counter --signer validator

npx will use project's terrain binary instead of the global one.

note that signer validator is one of a pre-configured accounts with balances on LocalTerra.

Deploy command will build and optimize wasm code, store it on the blockchain and instantiate the contract.

You can deploy to different network defined in the config.terrain.json (mainnet and testnet). But you can not use the pre-configured accounts anymore. So you need to first update your keys.terrain.js

// can use `process.env.SECRET_MNEMONIC` or `process.env.SECRET_PRIV_KEY`
// to populate secret in CI environment instead of hardcoding

module.exports = {
  custom_tester_1: {
    mnemonic:
      "shiver position copy catalog upset verify cheap library enjoy extend second peasant basic kit polar business document shrug pass chuckle lottery blind ecology stand",
  },
  custom_tester_2: {
    privateKey: "fGl1yNoUnnNUqTUXXhxH9vJU0htlz9lWwBt3fQw+ixw=",
  },
};

Apparently, there are some example accounts pre-defined in there. But DON'T USE THEM ON MAINNET since it is not a secret anymore.

For demonstration purpose, we are going to use custom_tester_1.

First, get some Luna from the faucet to pay for gas. Notice that it requires address but you only have mnenomic or private_key in keys.terrain.js.

The easiest way to retrive the address is to use console:

npx terrain console

terrain > wallets.custom_tester_1.key.accAddress
'terra1qd9fwwgnwmwlu2csv49fgtum3rgms64s8tcavp'

Now you can request for Luna on the faucet then check your balance in console.

terrain > (await client.bank.balance(wallets.custom_tester_1.key.accAddress))[0]

client is an LCDClient (LCD stands for "Light Client Daemon" as opposed to FCD a "Fulll Client Daemon", if you are curious) with some extra utility function. And wallets contains list of Wallet.

npx terrain deploy counter --signer custom_tester_1 --network testnet

Same goes for mainnet deployment, you might want to store your secrets in enviroment variable instead, which you can populate them through process.env.SOME_SECRET in keys.terrain.json.

You can also separate storing code from contract instantiation as using:

After deployment, refs.terrain.json will get updated. Refs file contains contract references on all network.

{
  "localterra": {
    "counter": {
      "codeId": "1",
      "contractAddresses": {
        "default": "terra18vd8fpwxzck93qlwghaj6arh4p7c5n896xzem5"
      }
    }
  },
  "testnet": {
    "counter": {
      "codeId": "18160",
      "contractAddresses": {
        "default": "terra15faphq99pap3fr0dwk46826uqr2usve739l7ms"
      }
    }
  }
}

This information is used by terrain's utility functions and also the frontend template.

But in order to use it with frontend, You sync this in to frontend/src since it can not import file outside its rootDir (src). Todo so, run:

npx terrain sync-refs

This is not ideal, ideas and contribution are more than welcome

With this, we can now start frontend:

cd frontend
npm run start

Switching network in your terra wallet extension will result in referencing to different contract address in the respective network.

Lib, Console and Task

With the template setup, you can do this

npx terrain console
terrain > await lib.increment()
...
terrain > await lib.getCount()
{ count: 0 }

npx terrain console --network <NETWORK> is also possible

Where does this lib functions comes from?

The answer is here:

// lib/index.js

module.exports = ({ wallets, refs, config, client }) => ({
  getCount: () => client.query("counter", { get_count: {} }),
  increment: (signer = wallets.validator) =>
    client.execute(signer, "counter", { increment: {} }),
});

With this, you can interact with your contract or the blockchain interactively with your own abstractions.

You can use the lib to create task as well:

// tasks/example-with-lib.js

const { task } = require("@terra-money/terrain");
const lib = require("../lib");

task(async (env) => {
  const { getCount, increment } = lib(env);
  console.log("count 1 = ", await getCount());
  await increment();
  console.log("count 2 = ", await getCount());
});

To run this task:

npx terrain task:run example-with-lib

To create new task, run:

npx terrain task:new task-name

You might noticed by now that the env (wallets, refs, config, client) in task and lib are the ones that available in the console context.

Also, you can access terrajs in the console or import it in the lib or task to create custom interaction like in tasks/example-custom-logic.js or more complex one, if you are willing to do so, please consult terra.js doc.

// tasks/example-custom-logic.js

const { task, terrajs } = require("@terra-money/terrain");

// terrajs is basically re-exported terra.js (https://terra-money.github.io/terra.js/)

task(async ({ wallets, refs, config, client }) => {
  console.log("creating new key");
  const key = terrajs.MnemonicKey();
  console.log("private key", key.privateKey.toString("base64"));
  console.log("mnemonic", key.mnemonic);
});

Migrating CosmWasm contracts on Terra

(Thanks to @octalmage)

On Terra it is possible to initilize contracts as migratable. This functionallity allows the adminstrator to upload a new version of the contract, then send a migrate message to move to the new code.

We'll be using Terrain, a Terra development suite to ease the scaffolding, deployment, and migration of our contracts.

This tutorial builds on top of the Terrain Quick Start Guide.

Adding MigrateMsg to contract

There's two steps required to make a contract migratable:

  1. Smart contract handles the MigrateMsg transaction.
  2. Smart contract has an admin set, which is the address that's allowed to perform migrations.

To implement support for MigrateMsg you will need to add the message to msg.rs:

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct MigrateMsg {}

You can place this anywhere, I usually stick it above the InstantiateMsg struct.

With MigrateMsg defined we need to update contract.rs. First update the import from crate::msg to include MigrateMsg:

use crate::msg::{CountResponse, ExecuteMsg, InstantiateMsg, QueryMsg, MigrateMsg};

Then add the following method above instantiate:

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
    Ok(Response::default())
}

Calling migrate

In the previous Terrain tutorial we showed you how to deploy the contract, but we did not initilize it as migratable.

After adding MigrateMsg to the smart contract we can redeploy and add the --set-signer-as-admin flag. This tells Terra that the transaction signer is allowed to migrate the contract in the future.

npx terrain deploy counter --signer validator --set-signer-as-admin

With the new contract deployed you can make some changes, then migrate to the new code with the following command:

npx terrain contract:migrate counter --signer validator

Usage

$ npm install -g @terra-money/terrain
$ terrain COMMAND
running command...
$ terrain (-v|--version|version)
@terra-money/terrain/0.2.0 darwin-x64 node-v16.9.1
$ terrain --help [COMMAND]
USAGE
  $ terrain COMMAND
...

Commands

terrain code:new [NAME]

Generate new contract.

USAGE
  $ terrain code:new [NAME] [--path <value>] [--version <value>]

FLAGS
  --path=<value>     [default: ./contracts] path to keep the contracts
  --version=<value>  [default: 0.16]

DESCRIPTION
  Generate new contract.

See code: src/commands/code/new.ts

terrain code:store CONTRACT

Store code on chain.

USAGE
  $ terrain code:store [CONTRACT] --signer <value> [--no-rebuild] [--network <value>] [--config-path <value>]
    [--refs-path <value>] [--keys-path <value>] [--code-id <value>]

FLAGS
  --code-id=<value>
  --config-path=<value>  [default: ./config.terrain.json]
  --keys-path=<value>    [default: ./keys.terrain.js]
  --network=<value>      [default: localterra]
  --no-rebuild
  --refs-path=<value>    [default: ./refs.terrain.json]
  --signer=<value>       (required)

DESCRIPTION
  Store code on chain.

See code: src/commands/code/store.ts

terrain console

Start a repl console that provides context and convinient utilities to interact with the blockchain and your contracts.

USAGE
  $ terrain console [--network <value>] [--config-path <value>] [--refs-path <value>] [--keys-path <value>]

FLAGS
  --config-path=<value>  [default: config.terrain.json]
  --keys-path=<value>    [default: keys.terrain.js]
  --network=<value>      [default: localterra]
  --refs-path=<value>    [default: refs.terrain.json]

DESCRIPTION
  Start a repl console that provides context and convinient utilities to interact with the blockchain and your
  contracts.

See code: src/commands/console.ts

terrain contract:instantiate CONTRACT

Instantiate the contract.

USAGE
  $ terrain contract:instantiate [CONTRACT] --signer <value> [--network <value>] [--config-path <value>] [--refs-path
    <value>] [--keys-path <value>] [--instance-id <value>] [--code-id <value>] [--set-signer-as-admin]

FLAGS
  --code-id=<value>      target code id for migration, can do only once after columbus-5 upgrade
  --config-path=<value>  [default: ./config.terrain.json]
  --instance-id=<value>  [default: default]
  --keys-path=<value>    [default: ./keys.terrain.js]
  --network=<value>      [default: localterra]
  --refs-path=<value>    [default: ./refs.terrain.json]
  --set-signer-as-admin
  --signer=<value>       (required)

DESCRIPTION
  Instantiate the contract.

See code: src/commands/contract/instantiate.ts

terrain contract:migrate [CONTRACT]

Migrate the contract.

USAGE
  $ terrain contract:migrate [CONTRACT] --signer <value> [--no-rebuild] [--network <value>] [--config-path <value>]
    [--refs-path <value>] [--keys-path <value>] [--instance-id <value>] [--code-id <value>]

FLAGS
  --code-id=<value>      target code id for migration
  --config-path=<value>  [default: ./config.terrain.json]
  --instance-id=<value>  [default: default]
  --keys-path=<value>    [default: ./keys.terrain.js]
  --network=<value>      [default: localterra]
  --no-rebuild           deploy the wasm bytecode as is.
  --refs-path=<value>    [default: ./refs.terrain.json]
  --signer=<value>       (required)

DESCRIPTION
  Migrate the contract.

See code: src/commands/contract/migrate.ts

terrain contract:updateAdmin CONTRACT ADMIN

Update the admin of a contract.

USAGE
  $ terrain contract:updateAdmin [CONTRACT] [ADMIN] --signer <value> [--network <value>] [--config-path <value>]
    [--refs-path <value>] [--keys-path <value>] [--instance-id <value>]

FLAGS
  --config-path=<value>  [default: ./config.terrain.json]
  --instance-id=<value>  [default: default]
  --keys-path=<value>    [default: ./keys.terrain.js]
  --network=<value>      [default: localterra]
  --refs-path=<value>    [default: ./refs.terrain.json]
  --signer=<value>       (required)

DESCRIPTION
  Update the admin of a contract.

See code: src/commands/contract/updateAdmin.ts

terrain deploy CONTRACT

Build wasm bytecode, store code on chain and instantiate.

USAGE
  $ terrain deploy [CONTRACT] --signer <value> [--no-rebuild] [--network <value>] [--config-path <value>]
    [--refs-path <value>] [--keys-path <value>] [--instance-id <value>] [--set-signer-as-admin] [--admin-address
    <value>] [--frontend-refs-path <value>] [--arm64]

FLAGS
  --admin-address=<value>       set custom address as contract admin to allow migration.
  --arm64                       use rust-optimizer-arm64 for optimization. Not recommended for production, but it will
                                optimize quicker on arm64 hardware during development.
  --config-path=<value>         [default: ./config.terrain.json]
  --frontend-refs-path=<value>  [default: ./frontend/src/refs.terrain.json]
  --instance-id=<value>         [default: default]
  --keys-path=<value>           [default: ./keys.terrain.js]
  --network=<value>             [default: localterra]
  --no-rebuild                  deploy the wasm bytecode as is.
  --refs-path=<value>           [default: ./refs.terrain.json]
  --set-signer-as-admin         set signer (deployer) as admin to allow migration.
  --signer=<value>              (required)

DESCRIPTION
  Build wasm bytecode, store code on chain and instantiate.

See code: src/commands/deploy.ts

terrain help [COMMAND]

display help for terrain

USAGE
  $ terrain help [COMMAND] [--all]

ARGUMENTS
  COMMAND  command to show help for

FLAGS
  --all  see all commands in CLI

DESCRIPTION
  display help for terrain

See code: @oclif/plugin-help

terrain new NAME

Create new dapp from template.

USAGE
  $ terrain new [NAME] [--path <value>] [--version <value>]

FLAGS
  --path=<value>     path to keep the project
  --version=<value>  [default: 0.16]

DESCRIPTION
  Create new dapp from template.

EXAMPLES
  $ terrain new awesome-dapp

  $ terrain new awesome-dapp --path path/to/dapp

See code: src/commands/new.ts

terrain sync-refs [FILE]

Sync configuration with frontend app.

USAGE
  $ terrain sync-refs [FILE] [--refs-path <value>] [--dest <value>]

FLAGS
  --dest=<value>       [default: ./frontend/src/refs.terrain.json]
  --refs-path=<value>  [default: ./refs.terrain.json]

DESCRIPTION
  Sync configuration with frontend app.

See code: src/commands/sync-refs.ts

terrain task:new [TASK]

create new task

USAGE
  $ terrain task:new [TASK]

DESCRIPTION
  create new task

See code: src/commands/task/new.ts

terrain task:run [TASK]

run predefined task

USAGE
  $ terrain task:run [TASK] [--network <value>] [--config-path <value>] [--refs-path <value>] [--keys-path
    <value>]

FLAGS
  --config-path=<value>  [default: config.terrain.json]
  --keys-path=<value>    [default: keys.terrain.js]
  --network=<value>      [default: localterra]
  --refs-path=<value>    [default: refs.terrain.json]

DESCRIPTION
  run predefined task

See code: src/commands/task/run.ts

terrain test CONTRACT-NAME

Runs unit tests for a contract directory.

USAGE
  $ terrain test [CONTRACT-NAME] [--no-fail-fast]

FLAGS
  --no-fail-fast  Run all tests regardless of failure.

DESCRIPTION
  Runs unit tests for a contract directory.

EXAMPLES
  $ terrain test counter

  $ terrain test counter --no-fail-fast

See code: src/commands/test.ts

Use main branch in local.

Sometimes the most new features or bugfixes are integrated into the main branch but not yet released to npm repository. In exceptional cases you may want to use the latest code of the library even before being released to @terra-money/terrain.

To use main branch in your local machine you must clone the repo and navigate to the project folder:

> git clone --branch main --depth 1 https://github.com/terra-money/terrain
> cd terrain/

Inside the project folder execute install, when it finish you can use link to setup the project as your global terrain instance:

> npm install
> npm link

Take in consideration that the process documented before sometimes will contain fixes and new features but is still being tested.

Comments
  • Terrain deploy counter sample will not build

    Terrain deploy counter sample will not build

    Fresh install of WSL2 Ubuntu, npm, rust, and localterra all installed to the latest version. When attempting to deploy the sample counter contract the build fails to parse manifest at /code/Cargo.toml and is caused by feature 'edition2021' is required.

    I followed the cargo docs linked in the error to fix and migrate to edition2021 and updated the Cargo.toml file to reflect that but still get the same error.

    The error also states that cargo version is 1.55.0, but as you can see below I have the latest cargo version installed (1.60.0). I was following terra docs exactly. Reinstalled ubuntu and tried again following the docs from every package instead with the same result.

    version: cargo -V cargo 1.60.0 (d1fd9fe 2022-03-01)

    command (npx has same results): npm terrain deploy counter --signer validatpr

    error: npx terrain deploy counter --signer validator using pre-baked 'validator' wallet on localterra as signer Compiling hex v0.4.3 Compiling byteorder v1.4.3 Compiling uint v0.9.3 Compiling cosmwasm-std v0.16.7 Compiling cw-storage-plus v0.8.1 Compiling cosmwasm-storage v0.16.0 Compiling cw2 v0.8.1 Compiling counter v0.1.0 (/home/stevenjacobs/developer/test-dapp/contracts/counter) Finished release [optimized] target(s) in 6.50s Running script 'optimize': 'docker run --rm -v "$(pwd)":/code --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry cosmwasm/rust-optimizer:0.12.3 ' Info: RUSTC_WRAPPER=sccache Info: sccache stats before build Compile requests 0 Compile requests executed 0 Cache hits 0 Cache misses 0 Cache timeouts 0 Cache read errors 0 Forced recaches 0 Cache write errors 0 Compilation failures 0 Cache errors 0 Non-cacheable compilations 0 Non-cacheable calls 0 Non-compilation calls 0 Unsupported compiler calls 0 Average cache write 0.000 s Average cache read miss 0.000 s Average cache read hit 0.000 s Failed distributed compilations 0 Cache location Local disk: "/root/.cache/sccache" Cache size 0 bytes Max cache size 10 GiB Building contract in /code ... error: failed to parse manifest at `/code/Cargo.toml

    Caused by: feature 'edition2021' is required

    The package requires the Cargo feature called 'edition2021', but that feature is not stabilized in this version of Cargo (1.55.0 (32da73ab1 2021-08-23)). Consider trying a newer version of Cargo (this may require the nightly release). See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2021 for more information about the status of this feature. Finished, status of exit status: 101 Error: ENOENT: no such file or directory, open 'artifacts/counter.wasm' Code: ENOENT`

    bug 
    opened by CompileSave 9
  • [BUG] - Terrain console not working on new Terrain template project - macOS M1 Max

    [BUG] - Terrain console not working on new Terrain template project - macOS M1 Max

    Issue description

    After creating a new project with terrain new and running npm install, the terrain console feature is not working on M1 MAX Macbook

    Node version tried: 16.13.2 16.14.2

    Steps to reproduce the issue

    1. terrain new testapp
    2. cd testapp
    3. npm install
    4. terrain console -> ERROR

    Error: Cannot find module '/Users/user/Documents/Terra/development/testapp/lib' Require stack: - /Users/user/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/lib/commands/console.js - /Users/user/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/config/lib/plugin.js - /Users/user/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/config/lib/config.js - /Users/user/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/config/lib/index.js - /Users/user/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/command/lib/command.js - /Users/user/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/command/lib/index.js - /Users/user/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/bin/run Code: MODULE_NOT_FOUND

    Even tried to deploy the contract first on LocalTerra, still not working

    Tools and operating system versions

    Macbook Pro 16" M1 MAX, 32GB, macOS Monterey 12.4

    $ npm -v && node -v && docker-compose -v && docker -v 8.5.0 v16.14.2 docker-compose version 1.29.2, build 5becea4c Docker version 20.10.14, build a224086

    bug 
    opened by ravenHSL 7
  • [FEATURE] While running

    [FEATURE] While running "terrain deploy counter --signer test1" got this error

    using pre-baked 'test1' wallet on localterra as signer Error: ENOENT: no such file or directory, chdir '/mnt/c/Users/Aravind Mandiga/Downloads/Fullstack/terra/clicker-portal' -> 'contracts/counter' Code: ENOENT

    I followed all steps correctly still got this error and unable to resolve

    opened by 0xAruu 7
  • [BUG] terrain console: MODULE_NOT_FOUND

    [BUG] terrain console: MODULE_NOT_FOUND

    Issue description

    terrain console can not be started due to

    Steps to reproduce the issue

    Following steps as described in https://docs.terra.money/docs/develop/terrain/using-terrain-localterra.html

    Start localterra:

    1. git clone --depth 1 https://github.com/terra-money/localterra
    2. cd localterra
    3. docker-compose up

    Create new dapp

    1. terrain new counter (instead of my-terra-dapp, see bug #93)
    2. cd counter
    3. npm install
    4. terrain deploy counter --signer test1
    5. terrain console

    Then I get this error: `$ terrain console

    Error: Cannot find module '/home/ttruong/data/development/counter/lib'
    Require stack:
    - /home/ttruong/.nvm/versions/node/v16.13.2/lib/node_modules/@terra-money/terrain/lib/commands/console.js
    - /home/ttruong/.nvm/versions/node/v16.13.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/config/lib/p
    lugin.js
    - /home/ttruong/.nvm/versions/node/v16.13.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/config/lib/c
    onfig.js
    - /home/ttruong/.nvm/versions/node/v16.13.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/config/lib/i
    ndex.js
    - /home/ttruong/.nvm/versions/node/v16.13.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/command/lib/
    command.js
    - /home/ttruong/.nvm/versions/node/v16.13.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/command/lib/
    index.js
    - /home/ttruong/.nvm/versions/node/v16.13.2/lib/node_modules/@terra-money/terrain/bin/run
    Code: MODULE_NOT_FOUND
    

    `

    Tools and operating system versions

    $ npm -v && node -v && docker-compose -v && docker -v && terrain --version 8.1.2 v16.13.2 docker-compose version 1.28.5, build c4eb3a1f Docker version 20.10.17, build 100c701 @terra-money/terrain/0.4.1 linux-x64 node-v16.13.2

    bug 
    opened by taitruong 6
  • [BUG] Dock run error on windows (Cargo.toml)

    [BUG] Dock run error on windows (Cargo.toml)

    Issue description

    I try to run npx terrain deploy counter --signer validator in windows. This fails with error message on $(pwd).

    Steps to reproduce the issue

    1. Run npx terrain deploy counter --signer validator in windows.
    2. Error message: docker: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path. See 'docker run --help'. Error: Command failed: docker run --rm -v "$(pwd)":/code --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry
      cosmwasm/rust-optimizer:0.12.5

    Tools and operating system versions

    Operating system: windows 10

    From what I found the error is caused because windows doesn't recognize $(pwd) and it should be %cd% instead. The docker -run call leading to this error can be found under folder /counter in file Cargo.toml. Modifying pwd to cd in this file doesn't work because this file is regenerated after every run. I have for the moment no idea where this generation happens so I am not able to modify pwd.

    bug 
    opened by ToniBar 5
  • Replace cargo generate

    Replace cargo generate

    This PR will replace cargo generate with template-scaffolding which is a native JavaScript solution to clone templates and replace the tags from the template with necessary values send as config object.

    opened by emidev98 5
  • [BUG] terrain console is unable to execute lib functions in example template

    [BUG] terrain console is unable to execute lib functions in example template

    Issue description

    When trying to execute the functions provided in the lib/index.ts file via terrain console, I receive an error regarding undefined contractAddresses from ContractRefs.

    Steps to reproduce the issue

    1. Setup new dapp template (terrain new example_dapp)
    2. Start up local Terra
    3. terrain deploy example_dapp
    4. terrain console > lib.increment()
    5. See error.

    Tools and operating system versions

    8.11.0 v16.16.0 docker-compose version 1.27.2, build 18f557f9 Docker version 20.10.15, build fd82621 @terra-money/terrain/0.4.1 linux-x64 node-v16.16.0

    Additional details / screenshot

    image

    bug 
    opened by dominictwlee 4
  • EPERM: operation not permitted, rename

    EPERM: operation not permitted, rename

    Issue description

    Getting EPERM: operation not permitted, rename tried uninstalling and installing tried using administrator tried using gitbash and cmd on windows tried npm cache clean --force

    Steps to reproduce the issue

    npm install -g @terra-money/terrain on windows 10 with node v16.13.1

    Additional details / screenshot

    generating app my-terra-dapp:
    - workspace... !
        Error: EPERM: operation not permitted, rename
        '.unzipped\terrain-core-template-main' ->
        'C:\Users\xyz\Documents\localterra\my-terra-dapp'
        Code: EPERM```
    
    bug 
    opened by vinodhum 4
  • Help command doesn't work out-of-box

    Help command doesn't work out-of-box

    Steps to reproduce:

    npx @terra-money/terrain --help

    Error: Unable to load configured help class "./src/lib/help", failed with message:
    Cannot find module '/Users/***/.npm/_npx/02559bbcf34ab2a9/node_modules/@terra-money/terrain/src/lib/help'
    

    That fails because package folder structure is @terra-money/terrain/lib/lib/help not @terra-money/terrain/src/lib/help

    bug 
    opened by imaai 4
  • Terrain quickstart guide failing on MacOS with

    Terrain quickstart guide failing on MacOS with "cannot get submodules without a working tree" error

    Hi folks,

    I've been trying all afternoon to get the Terrain quickstart up and going on my Intel MacBook Pro. I've been following the instructions here:

    https://docs.terra.money/docs/develop/dapp/quick-start/README.html

    In summary:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    rustup default stable
    rustup target add wasm32-unknown-unknown
    cargo install cargo-generate --features vendored-openssl
    cargo install cargo-run-script
    
    nvm use 16     # see: https://github.com/nvm-sh/nvm
    
    npm install -g @terra-money/terrain
    

    All of the above works, but when I attempt to generate the scaffold, this happens:

    › terrain new my-terra-dapp
    generating:
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { code: -1, klass: 17, message: "cannot get submodules without a working tree" }', /Users/dan/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-generate-0.13.0/src/git/utils.rs:203:38
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    - contract... !
        Error: Command failed: cargo generate --git https://github.com/CosmWasm/cw-template.git --branch 0.16 --name
        counter
        thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { code: -1, klass: 17, message:
        "cannot get submodules without a working tree" }',
        /Users/dan/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-generate-0.13.0/src/git/utils.rs:203:38
        note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    Initially I thought perhaps Terrain might have straight up been broken, so I attempted to repro with a Dockerfile, only to discover that it worked.

    Any ideas what might be wrong?

    Cheers, Dan.

    MacOS version: 12.3.1 (21E258)

    bug 
    opened by dan-turner 4
  • terrain deploy not working with the latest version of  `cosmwasm-std` and `cw2`

    terrain deploy not working with the latest version of `cosmwasm-std` and `cw2`

    This is the latest version tested that is supported (I can deploy with)

    [dependencies]
    cosmwasm-std = { version =  "0.16.7" }
    cw-storage-plus = "0.9.1"
    cw2 = "0.9.1"
    

    This is the latest version:

    [dependencies]
    cosmwasm-std = { version =  "1.0.0-beta8" }
    cw-storage-plus = "0.13.2"
    cw2 = "0.13.2"
    

    Not too sure where to open the issue because there is so many moving parts.

    Here's the output

    using pre-baked 'test1' wallet on localterra as signer
       Compiling counter v0.1.0 ()
        Finished release [optimized] target(s) in 3.89s
    Info: RUSTC_WRAPPER=sccache
    Info: sccache stats before build
    Compile requests                      0
    Compile requests executed             0
    Cache hits                            0
    Cache misses                          0
    Cache timeouts                        0
    Cache read errors                     0
    Forced recaches                       0
    Cache write errors                    0
    Compilation failures                  0
    Cache errors                          0
    Non-cacheable compilations            0
    Non-cacheable calls                   0
    Non-compilation calls                 0
    Unsupported compiler calls            0
    Average cache write               0.000 s
    Average cache read miss           0.000 s
    Average cache read hit            0.000 s
    Failed distributed compilations       0
    Cache location                  Local disk: "/root/.cache/sccache"
    Cache size                            0 bytes
    Max cache size                       10 GiB
    Building contract in /code ...
       Compiling counter v0.1.0 (/code)
        Finished release [optimized] target(s) in 6.57s
    Creating intermediate hash for counter.wasm ...
    0021a28c982c969c1d8421fda0a2960ecca637f715564d07fb5141ea051cb6a8  ./target/wasm32-unknown-unknown/release/counter.wasm
    Optimizing counter.wasm ...
    Creating hashes ...
    279b6fb77b3095b3ce37eeb2960e16a5dd8146c04c9da9ef48f279bf0ac549de  counter.wasm
    Info: sccache stats after build
    Compile requests                      1
    Compile requests executed             0
    Cache hits                            0
    Cache misses                          0
    Cache timeouts                        0
    Cache read errors                     0
    Forced recaches                       0
    Cache write errors                    0
    Compilation failures                  0
    Cache errors                          0
    Non-cacheable compilations            0
    Non-cacheable calls                   1
    Non-compilation calls                 0
    Unsupported compiler calls            0
    Average cache write               0.000 s
    Average cache read miss           0.000 s
    Average cache read hit            0.000 s
    Failed distributed compilations       0
    
    Non-cacheable reasons:
    crate-type                            1
    
    Cache location                  Local disk: "/root/.cache/sccache"
    Cache size                            0 bytes
    Max cache size                       10 GiB
    done
    storing wasm bytecode on chain... !
        Error: Request failed with status code 400
        Response: failed to execute message; message index: 0: Error calling the VM: Error during static
         Wasm validation: Wasm contract has unknown interface_version_* marker export (see 
        https://github.com/CosmWasm/cosmwasm/blob/main/packages/vm/README.md): store wasm contract 
        failed: invalid request
    
    bug 
    opened by ElasticBottle 3
  • [BUG] Deploying to terra classic failed.

    [BUG] Deploying to terra classic failed.

    Issue description

    Insufficient error even I have enough lunc in my wallet.

    Steps to reproduce the issue

    I added this chain (classic) to config.json file. "classic": { "_connection": { "chainID": "columbus-5", "URL": "https://lcd.terra.dev" } }, And add wallet mnemonic to keys.terrain.js. Then ran this command. terrain deploy --signer classic --network classic --config-path= Wallet address: https://finder.terra.money/classic/address/terra13tyuvrpf0hxye2n3e4w8jchl5738wycp5fh974

    Tools and operating system versions

    "@terra-money/terrain": "^0.5.8"

    Additional details / screenshot

    • Screenshot- image
    bug 
    opened by trust0212 0
  • [BUG]

    [BUG]

    Issue description

    When trying to deploy a contract that implements another contract as a dependency to LocalTerra, the rust optimizer fails

    Steps to reproduce the issue

    When trying to deploy a contract using terrain

    [dependencies]
    mycontract = { path="../mycontract", version = "0.1.0", features=["library"]}
    
    $ terrain deploy mymaincontract --signer validator
    

    Result :

    Building contract in /code ...
    error: failed to get `mycontract` as a dependency of package `mymaincontract v0.1.0 (/code)`
    
    Caused by:
      failed to load source for dependency `mycontract`
    
    Caused by:
      Unable to update /mycontract
    
    Caused by:
      failed to read `/mycontract/Cargo.toml`
    
    Caused by:
      No such file or directory (os error 2)
    node:internal/errors:841
      const err = new Error(message);
                  ^
    
    Error: Command failed: docker run --rm -v "$(pwd)":/code       --mount type=volume,source="mymaincontract_cache",target=/code/target       --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry       cosmwasm/rust-optimizer:0.12.6
        at checkExecSyncError (node:child_process:828:11)
        at Object.execSync (node:child_process:899:15)
        at execDockerOptimization (/home/kargath/.nvm/versions/node/v16.16.0/lib/node_modules/@terra-money/terrain/lib/lib/deployment.js:30:21)
        at optimizeContract (/home/kargath/.nvm/versions/node/v16.16.0/lib/node_modules/@terra-money/terrain/lib/lib/deployment.js:40:5)
        at Object.exports.optimize (/home/kargath/.nvm/versions/node/v16.16.0/lib/node_modules/@terra-money/terrain/lib/lib/deployment.js:53:9)
        at Object.exports.storeCode (/home/kargath/.nvm/versions/node/v16.16.0/lib/node_modules/@terra-money/terrain/lib/lib/deployment.js:60:23)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async Deploy.run (/home/kargath/.nvm/versions/node/v16.16.0/lib/node_modules/@terra-money/terrain/lib/commands/deploy.js:43:28)
        at async Deploy._run (/home/kargath/.nvm/versions/node/v16.16.0/lib/node_modules/@terra-money/terrain/node_modules/@oclif/command/lib/command.js:43:20) {
      status: 101,
      signal: null,
      output: [ null, null, null ],
      pid: 52532,
      stdout: null,
      stderr: null
    }
    
    
    
    

    Any insights? Thank you !

    bug 
    opened by HamzaKarh 0
  • [FEATURE] Allow users to have addresses in config.terrain.json

    [FEATURE] Allow users to have addresses in config.terrain.json

    Describe the feature

    Create new field on config.terrain.json that allow the user to setup mnemonics or private keys.

    Describe the solution you'd like

    The config.terrain.json could look like:

    {
        ...,
        "wallets" : {
            "[mnemonicName]": {
                "mnemonic": "...",
            },
            "[privateKeyName]": {
                "privateKey": "...",
            }
        },
        ....
    }
    

    Where [mnemonicName] or [privateKeyName] can be the value for **--signer ** parameter when a user has to sign a TX

    feature request 
    opened by emidev98 0
  • [FEATURE] Linting compliant

    [FEATURE] Linting compliant

    Describe the feature

    Make the project to be eslint compliant.

    Describe the solution you'd like

    Configure eslint --fix or prettier to apply the format to majority of rules and adjust the other rules that maybe not necessary.

    Describe alternatives you've considered

    Leave just the basic rules which prettier can fix.

    feature request 
    opened by emidev98 0
  • Reading mnemonic from keychain

    Reading mnemonic from keychain

    Idea

    In thread with #39 I was thinking whether support should be added for reading the signer's mnemonic from the local device's keychain, rather than hardcoded config or ENV vars.

    Keychains on Linux, Mac OS and Windows provides encrypted storage with access-gating by the logged in user, and should thus be a safer storage option than exporting ENV or saving static config files.

    It should be opt-in and not the default option, to ensure that this is not a breaking change to terrain

    Implementation

    Expand on wallet:new (if #41 is accepted and merged) so it can --store-to-keychain=<name>. Name would be the name of the secret to register in the keychain, and it could default to signer_mnemonic or so.

    Additionally a wallet:store command can be added to save either the content of a file (with a mnemonic) or via standard-in, into the keychain.

    Finally, adding support for setting an env-var like SECRET_FROM_KEYCHAIN_NAME=<name> which would supercede all other secret vars or config, and instruct terrain to read the mnemonic from the keychain.

    The node-js package keytar from https://github.com/atom/node-keytar works cross platform and has a very easy to use async interface for writing and reading keychain data. I have just verified it working on Ubuntu, mac OS and Windows without hassle.

    enhancement 
    opened by 0xlaine 5
  • Template frontend breaks on every hot refresh with Terra Station Extension

    Template frontend breaks on every hot refresh with Terra Station Extension

    As per the title, the template React app generated by terrain new crashes every time a change triggers a hot reload. Fixing requires a manual refresh each time.

    Here's the error: image

    Impact Have to manually refresh app after every change.

    Steps to replicate

    1. Run terrain new app
    2. cd app and then npm i
    3. npm start
    4. Make a change that triggers hot reload (type a space, add a console log, etc.)
    5. App crashes and needs to be manually reloaded

    Environment @terra-money/terrain/0.2.0 darwin-arm64 node-v16.14.2 Terra Station Wallet extenstion version 2.8.2 "@terra-dev/use-wallet": "^2.5.2", "@terra-money/terra.js": "^3.0.11", "@terra-money/wallet-provider": "^3.8.1", Node v16.14.2 Npm v8.5.0 MacOS 12.3.1 Google Chrome Version 100.0.4896.127 (Official Build) (arm64)

    bug 
    opened by AlmostEfficient 3
Releases(v0.7.0)
Owner
Terra
The official repositories for the Terra
Terra
mirrord lets you easily mirror traffic from your production environment to your development environment.

mirrord lets you easily mirror traffic from your Kubernetes cluster to your development environment. It comes as both Visual Studio Code extension and a CLI tool.

MetalBear 2.1k Dec 24, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
SmartBuilder: A Block-based Visual Programming Framework for Smart Contract Development

SmartBuilder A Block-based Visual Programming Framework for Smart Contract Development Technology stack used SmartBuilder Framework - Google Blockly A

ibelab 4 Mar 29, 2022
A little practice dapp for ethereum smart contract development.

Basic Sample Hardhat Project This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample s

Andres Vidoza 9 Sep 28, 2022
This is a development platform to quickly generate, develop & deploy smart contract based applications on StarkNet.

generator-starknet This is a development platform to quickly generate, develop, & deploy smart contract based apps on StarkNet. Installation First, in

Only Dust 34 Nov 18, 2022
I’m a very useful music bot that can make you play a music with a simple command! I have a lot of good commands that you can have a better experience playing your favorites songs!

I’m a very useful music bot that can make you play a music with a simple command! I have a lot of good commands that you can have a better experience playing your favorites songs!

Hugo Kishi 2 Aug 16, 2022
An extension for rating the web and making your browsing experience better than ever.

Hookmark An extension for rating the web and making your browsing experience better than ever. Read more about it here Update Firefox extension was un

Haridarshan Choudhary 9 Sep 17, 2022
lottery smart contract with react UI, Now ready to interact

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: ya

Akshay Kurhekar 1 Dec 19, 2021
First smart contract deployed on Rinkeby.

Inbox-Contract First smart contract deployed on Rinkeby. It has a basic constructor which accpets a string and assigns the string to the message varia

Stanley Moukhametzianov 1 Dec 26, 2021
Uniswapv2-pool-funding - A "Nugget Standard for Funding" compliant smart contract to provide liquidity to UniswapV2 (clone) pools. (Quickswap in this case)

uniswap(clone)-v2-pool-funding A smart contract that makes it easy to: supply liquidity to a uniswap(clone)-v2 pool using ERC20 or the network native

null 2 May 14, 2022
Web3-citizens-app - React application based on smart contract using web3 and MetaMask extention.

Citizens App (web3-react-redux) React application based on smart contract using web3 and MetaMask extention. Start the applicarion Recomend to install

Denys Voloshyn 3 Aug 25, 2022
SmartContract UI Open source Blockchain's Smart Contract Tool

SmartContract UI Open source Blockchain's Smart Contract Tool Table of contents Homepage Features Usage Config ABI Import from deployed contract Selec

Martin Pham 12 Dec 16, 2022
Aergo Timer Service schedule smart contract function calls

Aergo Timer Service ⏰ Create timers to call functions on your smart contracts Schedule calls based on time interval or on specific date-times For a sm

aergo 3 Mar 10, 2022
Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

Hajar OUAAROUCH 5 May 24, 2022
Smart contracts for governance. Contract allows to bond custom/LP UNI-v2 tokens and get voting power

Smart contracts for governance. Contract allows to bond custom/LP UNI-v2 tokens and get voting power

Rinat Fihtengolts 3 Oct 2, 2022
Ethereum smart contract gas cost waste pattern detection and patching tool

Ethereum smart contract gas cost waste pattern detection and patching tool

ibelab 4 Mar 23, 2022
A simple multilateral escrow smart contract for ETH and ERC-20 tokens governed by Cobie.

Multilateral Escrow Smart Contract Governed by Cobie Test Deployments Cobie's address: 0x4Cbe68d825d21cB4978F56815613eeD06Cf30152 Rinkeby: 0xFfE420602

Pascal Marco Caversaccio 28 Dec 15, 2022
This repository contains the Solidity smart contract of Enso, a detailed list of features and deployment instructions.

Enso NFT Smart Contract This repository contains the Solidity smart contract of Enso, a detailed list of features and deployment instructions. We stro

enso NFT 3 Apr 24, 2022