Instruction

Instruction

Unlike Truffle being an hardcoded environment where the configuration sticked to only Ethereum, Houston separated configuration and account layer from migration component in order to handle situation for an environment where contracts has to be deployed to multiple blockchains but shares webassembly + JSON ABI schema for developing them.

Instruction is the higher order component which returns a component with network option, ABI methods, and default test account wallets to be run in migration scripts. Instruction makes Houston versatile developing smart contract on every blockchain which uses rust as smart contract.

For example, to deploy a smart contract in multiple networks in Truffle, one must create multiple projects in which the network configuration is fixed to only one network with truffle-config.js. Developers also need to understand each blockchain's client SDK to interact with the smart contract on each network. On the other hand, Houston just needs to import instruction library to setup and interact with the contract. Developers just need to understand high-level apis of instruction.

To get a preset configuration for curated networks write:

import Instruction from '@terra-money/instruction'

async function migrate() {
    // Terra deployment
    const FLIPPER_TERRA = Instruction.require('flipper', 'localterra', {signer: 'default0'});
    await FLIPPER_TERRA.storeCode();
    await FLIPPER_TERRA.instantiate(true);
    // Secret deployment
    const FLIPPER_SECRET = Instruction.require('flipper', 'secret', {signer: 'default'});
    await FLIPPER_SECRET.storeCode();
    await FLIPPER_SECRET.instantiate(true);
}

migrate()

You can declare your own network configuration from the class Instruction in a separate code and use it for deploying your smart contracts:

import Instruction from '@terra-money/instruction'

const CUSTOM = Instruction.declare({
    //... custom options and client integration for the network
})

async function migrate() {
    const FLIPPER_CUSTOM = Custom.require('flipper', {signer: 'default0'});
    await FLIPPER_CUSTOM.storeCode();
    await FLIPPER_CUSTOM.instantiate(true);
    await FLIPPER.flip();
}

migrate()

Accessing existing contract in the network

To interact with an existing contract which is already deployed in the network, a contract address and corresponding ABI json files are required. ABI json files are retrieved from Instruction by specifying contract name in the project.

import Instruction from '@terra-money/instruction'

const FLIPPER = Instruction.at('flipper', 'localterra');

async function migrate() {
    await FLIPPER.flip();
}

migrate()

Last updated