Coder Social home page Coder Social logo

terra-money / terrain Goto Github PK

View Code? Open in Web Editor NEW
47.0 5.0 37.0 1.74 MB

๐Ÿ›  A Terra development environment for seamless smart contract development

Home Page: https://docs.terra.money/develop/guides/initial

License: GNU General Public License v3.0

JavaScript 1.53% Batchfile 0.04% TypeScript 98.44%
blockchain cosmwasm cryptocurrency smart-contracts terra web3 smart-contract-deployment smart-contract-tools non-fungible-token

terrain's Introduction

Terrain

Terrain banner

Terrain - A development environment for seamless smart contract development on the interchain.


Terrain allows you to:

  • Scaffoldย a template smart contract and frontend for interchain app development.
  • Dramatically simplify the development and deployment process.

Terrain is not:

  • A fully-featured command-line interface (CLI). If you need a fully-featured client for Terra, use terrad.
  • A Light Client Daemon (LCD). You will still need an RPC endpoint to deploy your contract. A local chain like LocalTerra is the recommended option for this.

Table of contents

Setup

Download LocalTerra

For testing purposes, we recommend to install and run LocalTerra on your personal computer. Instructions on how to get LocalTerra up and running can be found in the LocalTerra documentation.

Note: If you are using a Mac with an M1 chip, you might need to update your Docker Desktop due to the qemu bug.

Once all dependencies have been installed, do the following:

  1. Clone the LocalTerra repo.
git clone https://github.com/terra-money/LocalTerra.git
  1. Navigate to the newly created LocalTerra directory.
cd LocalTerra
  1. Spin up an instance of the environment with docker-compose.
docker-compose up

Setup Rust

While WASM smart contracts can be written in any programming language, it is strongly recommended that you use Rust, as it is the only language for which mature libraries and tooling exist for CosmWasm. To complete this tutorial, install the latest version of Rust by following the instructions here. Once Rust is installed on your computer, do the following:

  1. Set the default release channel used to update Rust to stable.
rustup default stable
  1. Add wasm as the compilation target.
rustup target add wasm32-unknown-unknown
  1. Install the necessary dependencies for generating contracts.
cargo install cargo-run-script

Install Node JS and NPM

To run Terrain, you will need to install version 16 of Node.js and download Node Package Manager (npm). It is recommend that you install Node.js v16 (LTS). If you download the LTS version of Node.js v16, npm will be automatically installed along with your download.

Getting Started

Now that you have completed the initial setup, generate your first smart contract using the procedure described below.

  1. Install the terrain package globally.
npm install -g @terra-money/terrain

Note: If you would like to install terrain locally, you can execute the command npm install @terra-money/terrain, without the -g flag, while in the directory in which you would like to be able to use the package. You can then execute any terrain commands by prefixing them with npx. For example, to scaffold a new project named my-terra-dapp with a locally installed terrain package, you would use the command npx terrain new my-terra-dapp.

  1. Generate your smart contract and corresponding frontend templates.
terrain new my-terra-dapp
  1. After the project is generated and all necessary Node dependencies are installed, navigate to the new my-terra-dapp directory to interact with your app.
cd my-terra-dapp

Project Structure

The terrain new command generates a project that contains a template smart contract, which is named after the specified app name, my-terra-dapp, and a corresponding frontend. Other supporting files are generated to provide further functionality. You may view the project structure below.

.
โ”œโ”€โ”€ contracts              # the smart contract directory
โ”‚ย ย  โ”œโ”€โ”€ my-terra-dapp      # template smart contract
โ”‚ย ย  โ””โ”€โ”€ ...
โ”œโ”€โ”€ frontend               # template frontend application
โ”œโ”€โ”€ lib                    # predefined task and console functions
โ”œโ”€โ”€ 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

Deployment

The terrain deploy command does the following:

  • Builds, optimizes, and stores the wasm code on the blockchain.
  • Instantiates the contract.

To deploy your new my-terra-dapp smart contract, run the following command in the terminal.

terrain deploy my-terra-dapp --signer test1

In this case, we specify one of the preconfigured accounts with balances on LocalTerra, test1, as our signer. The signer account will be responsible for paying the gas fee associated with deploying the contract to the Terra blockchain and will be assigned as the owner of the project.

You can also specify the network on which you would like to deploy your contract by adding the --network flag. If the network is not specified, as is the case in our above example, your contract will be deployed to localterra by default. If your deployment command in the prior step resulted in an error, you will need to ensure that LocalTerra is up and running in the background and that you have properly spelled out your contract name and are utilizing the appropriate Terrain command. You may also deploy to mainnet, the live Terra blockchain, as well as testnet, a network similar to mainnet used for testing.

Step-by-step Deployment

You can also execute the build, optimize, store, and instantiate processes separately by executing the following commands in sequential order.

  1. terrain contract:build CONTRACT
  2. terrain contract:optimize CONTRACT
  3. terrain contract:store CONTRACT
  4. terrain contract:instantiate CONTRACT

Afterward, you will have to run the terrain sync-refs command in your project directory to sync the refs.terrain.json file in the app root directory to the frontend directory. This file contains references to all contracts in the project which have been stored on any Terra network.


Deploying on Testnet or Mainnet

The predefined accounts in the keys.terrain.js file shown below can be used as signers on testnet. We will demonstrate how to deploy your smart contract utilizing the preconfigured custom_tester_1 account. You may also add a personal account to the keys.terrain.js file by adding the account name as well as its corresponding private key. You can then use that account as the signer specifying the account name after the --signer flag in the terrain deploy command.

Warning: Utilizing a personal account for deployment requires the use of a private key or mnemonic. These are private keys that are generated upon the creation of your personal wallet. Saving or utilizing these keys on your personal computer may expose them to malicious actors who could gain access to your personal wallet if they are able to obtain them. You can create a wallet solely for testing purposes to eliminate risk. Alternatively, you can store your private keys as secret environment variables which you can then reference utilizing process.env.SECRET_VAR in keys.terrain.json. Use your private key or mnemonic at your own discretion.

// 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=',
  },
};

Prior to deploying your contract, ensure that your signer wallet contains the funds needed to pay for associated transaction fees. You can request funds from the Terra Testnet Faucet by submitting the wallet address of the account where you would like to receive the funds and clicking on the Send me tokens button.

You can retrieve the wallet address associated with the custom_tester_1 account by executing the terrain console command in your terminal while in your project directory.

terrain console

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

After you have received the Luna tokens from the Terra Testnet Faucet, query the balance of your account by utilizing the following command in the terrain console.

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

Finally, exit the terrain console and deploy the counter smart contract to testnet with the custom_tester_1 account as the signer.

terrain deploy counter --signer custom_tester_1 --network testnet

Initializing the Frontend Template

After deployment, the refs.terrain.json file will be updated in the project directory as well as the frontend/src directory. These files contain references to all contracts inside of your project which have been stored on any Terra network. This information is used by terrain's utility functions and also the frontend template. An example of refs.terrain.json can be found below:

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

Important: If you have initialized the contract without using the terrain deploy command or have manually changed the refs.terrain.json file in the project directory, you will need to sync the references to the frontend/src directory in order to ensure frontend functionality. To do so, use the terrain sync-refs command.

After you have synced the contract references, navigate to the frontend directory and start the application.

  1. Navigate to the frontend directory.
cd frontend
  1. Start the application.
npm run start

Note: Switching networks in your Terra Station extension will result in a change in reference to the contract address which corresponds with the new network.

Run Contract Functions with Terrain

Once you have successfully deployed your project, you can interact with the deployed contract and the underlying blockchain by utilizing functions defined in the lib/index.js file. You may also create your own abstractions in this file for querying or executing transactions.

You can call the functions defined in lib/index.js inside of the terrain console. An example using the template counter smart contract is shown below.

terrain console
terrain > await lib.getCountQuery()
{ count: 0 }
terrain > await lib.increment()
terrain > await lib.getCountQuery()
{ count: 1 }

You may also specify which network you would like to interact with by utilizing the --network flag with the terrain console command.

terrain console --network NETWORK

Creating Tasks

You can use the functions available inside of the lib/index.js file to create tasks. Tasks are used in order to automate the execution of sequential functions or commands. An example task is provided for you in the tasks/example-with-lib.js file in your project directory.

// tasks/example-with-lib.js

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

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

To run the example task shown above, which is located in the tasks/example-with-lib.js file, run the following command in the terminal.

terrain task:run example-with-lib

In order to create a new task, run the following command replacing <task-name> with the desired name for your new task.

terrain task:new <task-name>

If you would like to use JavaScript in your functions or tasks, you can import Feather.js. The tasks/example-custom-logic.js file contains an example of a task that uses Terra.js functionality. To learn more about Terra.js, view the Terra.js documentation.

// tasks/example-custom-logic.js

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

// terrajs is basically re-exported terra.js (https://terra-money.github.io/feather.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);
});

Scripting deployments

As of Terrain 0.4.0 it is possible to deploy and instantiate contracts from tasks. This can be useful for multi-contract, or multi-stage deployments.

const { task } = require('@terra-money/terrain');

task(async ({ wallets, client, deploy }) => {
  // First deploy the counter smart contract.
  await deploy.storeCode('counter', wallets.test1);
  const counterAddress = await deploy.instantiate(
    // Contract name
    'counter',
    // Signer
    wallets.test1,
    {
      // Contract admin
      admin: wallets.test1.key.accAddress,
    },
  );

  // Now deploy a CW20 with the counter contract set as the minter in instantiation.
  await deploy.storeCode('cw20-base', wallets.test1);
  const cw20Address = await deploy.instantiate('cw20-base', wallets.test1, {
    admin: wallets.test1.key.accAddress,
    // Custom instantiation message.
    // with no message provided the default from config.terrain will be used.
    init: {
      name: 'counter',
      symbol: 'CTR',
      decimals: 6,
      initial_balances: [],
      mint: {
        minter: counterAddress,
      },
    },
  });

  // Update the CW20 address in counter.
  // Note: It's important to use the address returned by deploy.instantiate
  // Refs are only read into memory at the start of the task.
  await client.execute(counterAddress, wallets.test1, {
    update_token: { token: cw20Address },
  });

  console.log(`CW20 Address: ${cw20Address}`);
});

It is possible to tell Terrain to use a custom deploy task instead of the default deploy process. To do this, add the following to the global section in config.terrain.json:

"contracts": {
  "counter": {
    "deployTask": "deploy_counter"
  }
}

Now instead of running terrain task:run deploy_counter you can run terrain deploy counter.

Migrating CosmWasm Contracts on Terra

On Terra, it is possible to initialize a contract as migratable. This functionality allows the administrator to upload a new version of the contract and then send a migrate message to move to the new code. Contracts that have been deployed before implementing the following changes will not be able to be migrated and implemented changes will only be realized when redeploying the contract.

The contract migration tutorial builds on top of the Terrain Quick Start Guide and walks you through a contract migration.

Adding MigrateMsg to the Contract

In order for a contract to be migratable, it must be able to handle a MigrateMsg transaction.

To implement support for MigrateMsg, add the message to the msg.rs file. To do so, navigate to msg.rs and place the following code just above the InstantiateMsg struct.

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

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

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

Next, 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())
}

Migrating the Contract

Adding the MigrateMsg to the smart contract allows the contract's administrator to migrate the contract in the future. When we deploy our contract, the wallet address of the signer will be automatically designated as the contract administrator. In the following command, the contract is deployed with the preconfigured LocalTerra test1 wallet as the signer and administrator of our counter contract.

terrain deploy counter --signer test1

If you decide to make changes to the deployed contract, you can migrate to the updated code by executing the following command.

terrain contract:migrate counter --signer test1

If you would like to specify the address of the desired administrator for your smart contract, you may use the --admin-address flag in the deploy command followed by the wallet address of the desired administrator.

terrain deploy counter --signer test1 --admin-address <insert-admin-wallet-address>

Use Terrain Main Branch Locally

In some cases, the latest features or bug fixes may be integrated into the main branch of the Terrain Github repo, but not yet released to the corresponding npm package. Subsequently, you may want to use the latest version of Terrain available on Github before it has been released to npm. The below described method may also be used if you are interested in developing on and contributing to Terrain.

Warning: Features and bug fixes that are implemented on the latest version of Terrain may still be subject to testing. As such, you should only use the main branch of the Terrain github repo in exceptional circumstances. In all other cases, use the npm package.

To use the main branch of the Terrain repo on your local machine, follow the procedure below.

  1. Clone the repo.
git clone --branch main --depth 1 https://github.com/terra-money/terrain
  1. Navigate to the project folder.
cd terrain
  1. Inside the project folder, install all necessary node dependencies.
npm install
  1. Run the npm link command to set up the local repository as your global terrain instance.
npm link

If you would like to witness your changes immediately upon saving them, you may execute the following command while in your local Terrain directory and allow it to run in a tab in your terminal.

npm run watch

To unlink the terrain command from the cloned repository and revert back to the default functionality, you can execute the below command.

npm unlink terrain

Terrain Commands

terrain console

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

USAGE
  $ terrain console [--signer <value>] [--network mainnet|testnet|localterra] [--prefix <value>] [--refs-path
    <value>] [--keys-path <value>]

FLAGS
  --keys-path=<value>  [default: ./keys.terrain.js]
  --network=<option>   [default: localterra] network to deploy to from config.terrain.json
                       <options: mainnet|testnet|localterra>
  --prefix=<value>     [default: terra] address prefix of target chain, all chains supported by Station are supported by
                       terrain
  --refs-path=<value>  [default: ./refs.terrain.json]
  --signer=<value>     [default: test1]

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

See code: src/commands/console.ts

terrain contract:build CONTRACT

Build wasm bytecode.

USAGE
  $ terrain contract:build [CONTRACT] [--config-path <value>]

FLAGS
  --config-path=<value>  [default: ./config.terrain.json]

DESCRIPTION
  Build wasm bytecode.

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

terrain contract:instantiate CONTRACT

Instantiate the contract.

USAGE
  $ terrain contract:instantiate [CONTRACT] [--instance-id <value>] [--code-id <value>] [--signer <value>] [--network
    mainnet|testnet|localterra] [--prefix <value>] [--refs-path <value>] [--keys-path <value>]

FLAGS
  --code-id=<value>      specific codeId to instantiate
  --instance-id=<value>  [default: default] enable management of multiple instances of the same contract
  --keys-path=<value>    [default: ./keys.terrain.js]
  --network=<option>     [default: localterra] network to deploy to from config.terrain.json
                         <options: mainnet|testnet|localterra>
  --prefix=<value>       [default: terra] address prefix of target chain, all chains supported by Station are supported
                         by terrain
  --refs-path=<value>    [default: ./refs.terrain.json]
  --signer=<value>       [default: test1]

DESCRIPTION
  Instantiate the contract.

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

terrain contract:migrate CONTRACT

Migrate the contract.

USAGE
  $ terrain contract:migrate [CONTRACT] [--no-rebuild] [--instance-id <value>] [--code-id <value>] [--signer <value>]
    [--network mainnet|testnet|localterra] [--prefix <value>] [--refs-path <value>] [--keys-path <value>]

FLAGS
  --code-id=<value>      specific codeId to instantiate
  --instance-id=<value>  [default: default] enable management of multiple instances of the same contract
  --keys-path=<value>    [default: ./keys.terrain.js]
  --network=<option>     [default: localterra] network to deploy to from config.terrain.json
                         <options: mainnet|testnet|localterra>
  --no-rebuild           deploy the wasm bytecode as is.
  --prefix=<value>       [default: terra] address prefix of target chain, all chains supported by Station are supported
                         by terrain
  --refs-path=<value>    [default: ./refs.terrain.json]
  --signer=<value>       [default: test1]

DESCRIPTION
  Migrate the contract.

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

terrain contract:new NAME

Generate new contract.

USAGE
  $ terrain contract:new [NAME] [--path <value>] [--commitHash <value>] [--authors <value>]

FLAGS
  --authors=<value>     [default: Terra Money <[email protected]>]
  --commitHash=<value>  [default: 9fa5b9b38fca4f99239ac28be48a6e1f0a4d30c8]
  --path=<value>        [default: contracts] path to keep the contracts

DESCRIPTION
  Generate new contract.

EXAMPLES
  $ terrain code:new awesome_contract

  $ terrain code:new awesome_contract --path path/to/dapp

  $ terrain code:new awesome_contract --path path/to/dapp --authors "ExampleAuthor<[email protected]>"

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

terrain contract:optimize CONTRACT

Optimize wasm bytecode.

USAGE
  $ terrain contract:optimize [CONTRACT]

DESCRIPTION
  Optimize wasm bytecode.

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

terrain contract:schema CONTRACT

Generate contract schema.

USAGE
  $ terrain contract:schema [CONTRACT]

DESCRIPTION
  Generate contract schema.

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

terrain contract:store CONTRACT

Store code on chain.

USAGE
  $ terrain contract:store [CONTRACT] [--no-rebuild] [--code-id <value>] [--signer <value>] [--network
    mainnet|testnet|localterra] [--prefix <value>] [--refs-path <value>] [--keys-path <value>]

FLAGS
  --code-id=<value>    specific codeId to instantiate
  --keys-path=<value>  [default: ./keys.terrain.js]
  --network=<option>   [default: localterra] network to deploy to from config.terrain.json
                       <options: mainnet|testnet|localterra>
  --no-rebuild         deploy the wasm bytecode as is.
  --prefix=<value>     [default: terra] address prefix of target chain, all chains supported by Station are supported by
                       terrain
  --refs-path=<value>  [default: ./refs.terrain.json]
  --signer=<value>     [default: test1]

DESCRIPTION
  Store code on chain.

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

terrain contract:updateAdmin CONTRACT ADMIN

Update the admin of a contract.

USAGE
  $ terrain contract:updateAdmin [CONTRACT] [ADMIN] [--signer <value>] [--network mainnet|testnet|localterra] [--prefix
    <value>] [--instance-id <value>] [--refs-path <value>] [--keys-path <value>]

FLAGS
  --instance-id=<value>  [default: default] enable management of multiple instances of the same contract
  --keys-path=<value>    [default: ./keys.terrain.js]
  --network=<option>     [default: localterra] network to deploy to from config.terrain.json
                         <options: mainnet|testnet|localterra>
  --prefix=<value>       [default: terra] address prefix of target chain, all chains supported by Station are supported
                         by terrain
  --refs-path=<value>    [default: ./refs.terrain.json]
  --signer=<value>       [default: test1]

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] [--memo <value>] [--no-rebuild] [--instance-id <value>] [--frontend-refs-path
    <value>] [--admin-address <value>] [--no-sync <value>] [--signer <value>] [--network mainnet|testnet|localterra]
    [--prefix <value>] [--refs-path <value>] [--keys-path <value>]

FLAGS
  --admin-address=<value>       set custom address as contract admin to allow migration.
  --frontend-refs-path=<value>  [default: ./frontend/src/]
  --instance-id=<value>         [default: default] enable management of multiple instances of the same contract
  --keys-path=<value>           [default: ./keys.terrain.js]
  --memo=<value>                [default: terrain]
  --network=<option>            [default: localterra] network to deploy to from config.terrain.json
                                <options: mainnet|testnet|localterra>
  --no-rebuild                  deploy the wasm bytecode as is.
  --no-sync=<value>             don't attempt to sync contract refs to frontend.
  --prefix=<value>              [default: terra] address prefix of target chain, all chains supported by Station are
                                supported by terrain
  --refs-path=<value>           [default: ./refs.terrain.json]
  --signer=<value>              [default: test1]

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>] [--framework react|vue|svelte|next|vite|lit] [--version <value>]
    [--authors <value>]

FLAGS
  --authors=<value>     [default: Terra Money <[email protected]>]
  --framework=<option>  [default: react] Choose the frontend framework you want to use. Non-react framework options have
                        better wallet-provider support but less streamlined contract integration.
                        <options: react|vue|svelte|next|vite|lit>
  --path=<value>        [default: .] Path to create the workspace
  --version=<value>     [default: 1.0]

DESCRIPTION
  Create new dapp from template.

EXAMPLES
  $ terrain new awesome-dapp

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

  $ terrain new awesome-dapp --path path/to/dapp --authors "ExampleAuthor<[email protected]>"

  $ terrain new awesome-dapp --path path/to/dapp --framework vue --authors "ExampleAuthor<[email protected]>"

See code: src/commands/new.ts

terrain query CONTRACT MSG

Query contracts on the interchain

USAGE
  $ terrain query [CONTRACT] [MSG] [--network mainnet|testnet|localterra] [--config-path <value>]

ARGUMENTS
  CONTRACT  Contract address
  MSG       Query msg to be performed in JSON format

FLAGS
  --config-path=<value>  [default: ./config.terrain.json]
  --network=<option>     [default: localterra] network to deploy to from config.terrain.json
                         <options: mainnet|testnet|localterra>

DESCRIPTION
  Query contracts on the interchain

EXAMPLES
  $ terrain query terra1..fx9fs '{"get_count": {}}'

  $ terrain query juno1..af00x '{"get_count": {}}' --network testnet --config-path ../config.terrain.json

See code: src/commands/query.ts

terrain sync-refs

Sync configuration with frontend app.

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

FLAGS
  --dest=<value>       [default: ./frontend/src/]
  --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 a new task.

USAGE
  $ terrain task:new [TASK]

DESCRIPTION
  Create a new task.

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

terrain task:run [TASK]

run predefined task

USAGE
  $ terrain task:run [TASK] [--signer <value>] [--network mainnet|testnet|localterra] [--prefix <value>]
    [--refs-path <value>] [--keys-path <value>]

FLAGS
  --keys-path=<value>  [default: ./keys.terrain.js]
  --network=<option>   [default: localterra] network to deploy to from config.terrain.json
                       <options: mainnet|testnet|localterra>
  --prefix=<value>     [default: terra] address prefix of target chain, all chains supported by Station are supported by
                       terrain
  --refs-path=<value>  [default: ./refs.terrain.json]
  --signer=<value>     [default: test1]

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

terrain test:coverage [CONTRACT-NAME]

Runs unit tests for a contract directory.

USAGE
  $ terrain test:coverage [CONTRACT-NAME]

DESCRIPTION
  Runs unit tests for a contract directory.

EXAMPLES
  $ terrain test:coverage

  $ terrain test:coverage counter

See code: src/commands/test/coverage.ts

terrain tx CONTRACT MSG

Execute tx on the interchain

USAGE
  $ terrain tx [CONTRACT] [MSG] [--signer <value>] [--network mainnet|testnet|localterra] [--prefix
    <value>] [--refs-path <value>] [--keys-path <value>]

ARGUMENTS
  CONTRACT  Contract address
  MSG       Tx msg to be executed in JSON format

FLAGS
  --keys-path=<value>  [default: ./keys.terrain.js]
  --network=<option>   [default: localterra] network to deploy to from config.terrain.json
                       <options: mainnet|testnet|localterra>
  --prefix=<value>     [default: terra] address prefix of target chain, all chains supported by Station are supported by
                       terrain
  --refs-path=<value>  [default: ./refs.terrain.json]
  --signer=<value>     [default: test1]

DESCRIPTION
  Execute tx on the interchain

EXAMPLES
  $ terrain tx terra1..fx9fs '{"increment": {}}'

  $ terrain tx juno1..af00x '{"reset": {"count": 0}}' --network testnet

See code: src/commands/tx.ts

terrain wallet:new

Generate a new wallet to use for signing contracts.

USAGE
  $ terrain wallet:new [--outfile <value>] [--index <value>]

FLAGS
  --index=<value>    key index to use, default value is 0
  --outfile=<value>  absolute path to store the mnemonic key to. If omitted, output to stdout

DESCRIPTION
  Generate a new wallet to use for signing contracts.

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

terrain's People

Contributors

0xhkd avatar 0xlaine avatar emidev98 avatar erichgorski avatar evanorti avatar gregnuj avatar iboss-ptk avatar llllllluc avatar mijolae avatar octalmage avatar rtviii avatar snyk-bot avatar terran6 avatar vladjdk avatar vtno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

terrain's Issues

[FEATURE] Merge code and contract command

Describe the feature

Both code and contract operates within the same context, contract context, I would suggest to merge them into the contract command to simplify terrain's code base and make it easier for the user to understand that everything related to contract is packed inside contract prefix

Describe the solution you'd like

To move the commands from;

$ terrain code
Generate new contract.

USAGE
  $ terrain code:COMMAND

COMMANDS
  code:new    Generate new contract.
  code:store  Store code on chain.

$ terrain contract
Instantiate the contract.

USAGE
  $ terrain contract:COMMAND

COMMANDS
  contract:instantiate  Instantiate the contract.
  contract:migrate      Migrate the contract.
  contract:updateAdmin  Update the admin of a contract.

To the following structure:


$ terrain contract
Instantiate the contract.

USAGE
  $ terrain contract:COMMAND

COMMANDS
  contract:instantiate  Instantiate the contract.
  contract:migrate      Migrate the contract.
  contract:updateAdmin  Update the admin of a contract.
  contract:new          Generate new contract.
  contract:store        Store contract code on chain.

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```

Creating new wallet from terrain cli

Hi,

I was thinking it would be useful to be able to create / roll a new wallet via the terrain-cli rather than having to use Terra Station or Terra Chrome extension.

Would you accept a PR with such functionality?

Deploy a contract within the task

Hello,
Is it possible to write a task script that handles a terrain deploy contract command?

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

task(async ({ wallets, refs, config, client }) => {
  // terrain deploy counter --signer test1
});

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.

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] build failed

Issue description

Can somebody explain what I've missed?)

Steps to reproduce the issue

  1. On execute terrain deploy counter --signer test1 I got next error:
....
error[E0425]: cannot find function, tuple struct or tuple variant `Ok` in this scope
   --> /home/piron/.cargo/registry/src/github.com-1ecc6299db9ec823/hex-0.4.3/src/lib.rs:382:5
    |
382 |     Ok(())
    |     ^^ not found in this scope

error: build failed
    Error: Command failed: cargo wasm

Tools and operating system versions

node 16
ubuntu

[BUG] Unable to Deploy Counter contract to Local Terra

Issue description

I'm unable to deploy the test counter example to a localtest ran by localterra.

When trying to run "terrain deploy counter --signer test1 --arm64" I get the following error:
Response: unable to resolve type URL /cosmwasm.wasm.v1.MsgStoreCode: tx parse error: invalid request

Tools and operating system versions

NPM 8.11.0
NODE v16.15.1
docker-compose version 1.29.2, build 5becea4c
Docker version 20.10.14, build a224086

[FEATURE] Support workspace version in cargo

Describe the feature

Ideally we can define dependency version only in the root cargo.toml

[workspace.dependencies]
anyhow             = "1.0.75"
astroport          = "2.8.0"
bech32             = "0.9.1"
cosmwasm-schema    = "1.4.0"
cosmwasm-std       = "1.4.0"

Then in each contract's cargo.toml, we can just use the workspace's version by default like this

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std    = { workspace = true }

Describe the solution you'd like

Describe alternatives you've considered

Additional context

[BUG] terrain task:new tries copying files that don't exist.

Issue description

The terrain task:new command attempts copying from src/template/tasks/template.ts, but the files and tasks folder doesn't exist

Steps to reproduce the issue

  1. Create a new terrain project
  2. Run terrain task:new in that folder

Tools and operating system versions

$ npm -v && node -v && docker-compose -v && docker -v 
8.1.0
v16.13.0
docker-compose version 1.29.2, build unknown
Docker version 20.10.17, build 100c701

[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.

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] Replace - with _

Issue description

When creating a new app using - (hyphen-minus) should be translated to _ (underscore) since Rust does not allow - (hyphen-minus) as name for smart contract imports.

Steps to reproduce the issue

> terrain new token-factory
> cd token-factory/contracts/token-factory
> cargo test
   Compiling token-factory v0.1.0 (/token-factory/contracts/token-factory)
error: expected one of `::`, `;`, or `as`, found `-`
 --> examples/schema.rs:6:10
  |
6 | use token-factory::msg::{CountResponse, ExecuteMsg, InstantiateMsg, QueryMsg};
  |          ^ expected one of `::`, `;`, or `as`

error: could not compile `token-factory` due to previous error

Additional details

Study the possibility to also replace them in the frontend app if needed.

Incorrect account sequence will exist

Seems in previous commit, this problem are marked as solve. But seems my side still experiencing this problem.
But seems the problem is that store code may run a for a period of time, and the reusing the signer account will just outdate.

[BUG] terrain new my-terra-dapp: contract counter missing

Issue description

Creating a new dapp should contain counter contract template as described in https://docs.terra.money/docs/develop/terrain/using-terrain-localterra.html

Steps to reproduce the issue

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

  • clone and start localterra
  • create new dapp e.g. 'my-terra-dapp'

Under contracts there is my-terra-dapp but not counter. That would be ok, but it seems all over the places there are references to counter example. Like in lib/index.ts

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

Additional details / screenshot

  • Screenshot-

[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.

[BUG] Terrain task:run does not work with example tasks

Issue description

When trying to run the example tasks provided in the counter dapp template, I get typescript compilation error.

Steps to reproduce the issue

  1. Create new dapp from template.
  2. Run terrain task:run template, or with any of the other example tasks.
  3. 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

[FEATURE] Make terrain support cargo workspace

Describe the feature

Currently for projects created with terrain, if there are 2 contracts, they are isolated, i.e. when a contract is build, it only looks at the contract itself, but not the entire workspace, i.e. if i import pkg-1 in contract-1, it won't work.

|---contracts
|     |---contract-1
|     |---contract-2
|---packages
|     |---pkg-1
|     |---pkg-2
|---frontend
|---cargo.toml

Ideally when we run terrain deploy it will build the whole workspace and deploy all contracts, I believe this is what https://github.com/terra-money/terrariums does, i think we should merge terrain and terrariums.

Describe the solution you'd like

Describe alternatives you've considered

Additional context

Why removing the optimize in cargo.toml?

Starting the commit #17 , the rust-optimize command in repo is being ignore, and will use the one defined in the deploy.js.
However, as terrain is not supporting workspace, I got my own optimize script to run. Im really questioned, why making this change?

[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] - 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

[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

[BUG] terrain new my-terra-dapp some error

Issue description

terrain new my-terra-dapp has some error:

ModuleLoadError: [MODULE_NOT_FOUND] require failed to load C:\Users\tangc\AppData\Roaming\npm\node_modules@terra-money\terrain\lib\commands\new.js: Cannot find module
ยป '@terra-money/terra.proto/jax/tx'

Additional details / screenshot

Screenshot

Deploy socket hang up

terrain deploy counter --signer bb --network testnet

    Error: socket hang up
    Code: ECONNRESET

p.s im using Chinese network.

Terrain 0.2.0 CLI help is broken after fresh install

After a fresh install of terrain using node 16 on mac OS Monterey (x64 arch) the help command is broken...

Steps taken:

Get node and terrain

โฏ nvm install 16
โฏ npm install -g @terra-money/terrain

Dumping version info

โฏ terrain --version
@terra-money/terrain/0.2.0 darwin-x64 node-v16.14.2

Trying to run Terrain with no arguments is dead:

โฏ terrain
    Error: Unable to load configured help class "./src/lib/help", failed with message:
    Cannot find module '/Users/nover/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/src/lib/help'
    Require stack:
    - /Users/laine_ust/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/help/lib/util.js
    - /Users/laine_ust/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/help/lib/command.js
    - /Users/laine_ust/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/help/lib/index.js
    - /Users/laine_ust/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/command/lib/command.js
    - /Users/laine_ust/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/node_modules/@oclif/command/lib/index.js
    - /Users/laine_ust/.nvm/versions/node/v16.14.2/lib/node_modules/@terra-money/terrain/bin/run

Using specific commands like terrain console in a terrain scaffolded project works as expected - so it seems to only affect the help command.

[BUG] Unexpected behavior when running optimize

Issue description

Can't run optimize, error to compile lib bnum 0.7.0 dependent on cosmwasm-std

Steps to reproduce the issue

terrain contract:optimize my-dapp
...
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 bnum v0.7.0
error[E0599]: no method named cast_mut found for raw pointer *const [u8; 8] in the current scope
--> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/bnum-0.7.0/src/bint/endian.rs:77:47
|
77 | let ptr = uninit.as_ptr().cast_mut() as *mut u8;
| ^^^^^^^^ help: there is an associated function with a similar name: as_mut

Tools and operating system versions

Terrain 0.8.0
Rustc 1.71.1
Node v16.16.0

[FEATURE] Empty smart contract and frontend template

Describe the feature

For more experienced developers I would like to have an empty template that contains the entry points (Instantiate, Execute and Query) with hardcoded data and only one method per entry point.

The frontend should also comunicate to the smart contract in the proper way.

Describe the solution you'd like

When executing terrain new I would like to have the flag --template=empty which will scaffold a contract and frontend with the features explained above.

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

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)

[FEATURE] Move ./src/template to its own repo

Describe the feature

Based on allowing users to have different templates one of the important parts would be to move the content from ./src/template to its own repository. That way template-scaffolding can clone the root template on an easier way.

Describe the solution you'd like

Move "./src/template" to its own repository named "terrain-template" under terra-money org.

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] 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] 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

[FEATURE] Templates management

Describe the feature

Imagine a world where you could clone one of the different available contracts already prepared to work within Terrain workspace.

Describe the solution you'd like

Using one of the commands below you could initialize terrain with your favorite template to start developing your awesome app:

> terrain new [awesome-project-name] --template counter
> terrain new [awesome-project-name] --template cw20
> terrain new [awesome-project-name] --template cw721

This can be achieved by managing terra-money/terrain-frontend-template by branches with features for example a branch that could be the counter, cw20 (fungible token) or cw721 (non fungible token).

Afterwards a repository like terra-money/terrain-contracts-template will be a must to have with the the same structure as previously mentioned for the frontend code but this time with contracts. This repository will also open the doors to the creation of contracts like:

> terrain code:new [awesome-contract-name] --template counter
> terrain code:new [awesome-contract-name] --template cw20
> terrain code:new [awesome-contract-name] --template cw721

this code is subjected to #56 implementation

[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] PLEASE BUMP OPTIMIZER VERSION!!!!

Recommended solution

Bump optimizer version from 0.12.6 to 0.14.0 or latest.

Issue description

see more detail in my msg in cosmwasm discord

Steps to reproduce the issue

  1. Start a new cosmwasm repo, set cosmwasm-std version to 1.4.1 (latest, or any version >= 1.3)
  2. Use terrain or terrariums to deploy the code
  3. You will see bnum error like below, this is because bnum requires a higher rust version >= 1.65, current version of workspace optimizer use 0.12.6, which use rust 1.6, we need to bump workspace optimizer to 0.14.0 to fix it
   Compiling bnum v0.7.0
   Compiling serde_derive v1.0.189
   Compiling thiserror-impl v1.0.49
error[E0599]: no method named `cast_mut` found for raw pointer `*const [u8; 8]` in the current scope
   --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/bnum-0.7.0/src/bint/endian.rs:77:47
    |
77  |                     let ptr = uninit.as_ptr().cast_mut() as *mut u8;
    |                                               ^^^^^^^^ help: there is an associated function with a similar name: `as_mut`
...
225 | crate::macro_impl!(endian);
    | -------------------------- in this macro invocation
    |
    = note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref
    = note: using `<*const T>::as_ref()` on a pointer which is unaligned or points to invalid or uninitialized memory is undefined behavior
    = note: this error originates in the macro `endian` (in Nightly builds, run with -Z macro-backtrace for more info)

Temporary workaround

hardcode cw version to 1.2 cosmwasm-std = "=1.2" so it doesn't contain bnum, this can work with current terrain.

Tools and operating system versions

Additional details / screenshot

  • Screenshot-

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.