Hardhat equivalent for Cosmos-based chains that puts DevEx first – a productivity tool for easy contract development and deployment
The Problem
The main purpose of Warp is to provide an environment for smart contract developers and aid in the whole process of development – starting with scaffolding the project and ending on deploying the contracts to the network with just a single command.
The goal for this hackathon was to implement a blockchain abstraction layer for Warp and implement full support of the Secret Network (SCRT) on top of it.
The aim of Warp
Warp CLI aims to be a tool like Hardhat, but for Cosmos-based-chains. But unlike Hardhat, Warp does not provide one correct way to solve a problem. Instead, the toolchain takes inspiration from other chains, like EVM, Solana, Aptos, NEAR and more to provide first and foremost a customizable dev-experience. Inspired by those chains’ tooling, Warp aims to utilize its modular nature to let the person using it custom-tailor the tooling to their prefered work style. That way, the commands stay the same, but the functionality underneath can be customized. For people who do not want to test their contracts with Typescript, they can choose to execute rust-based integration tests instead, with the exact same, simple to use command. Same can be done for building contracts – if using Docker is not preferred, it can be customized in the settings.
With all that in mind, Warp CLI puts dev experience first and aims to be as pain-free and pleasant to use as Cargo, dotnet cli or npm are in the Web2.0 world.
Blockchain Abstraction Layer (BAL)
Originally, Warp was built for Secret Network in Q3 2022 for a personal project. While the network was maturing and growing, the team behind it worked on other projects and realized, that building DApps on Cosmos could use a tool like Warp on other chains – namely, Archway at that point in time. And so, Secret-Warp got forked and rewritten entirely from scratch for Archway. In that form it evolved and received many new features, putting the Secret version far behind.
With HackSecret 2024 the main goal was to not only implement support for SCRT in Warp, but also to make it so that adding any custom chain in the future can be a simple and pain-free process. The changes in architecture made the “chain profiles” act essentially as separate, modular plug-ins independent of the core functionality of Warp.
This has made Warp a truly cross-chain compatible tool suite, while also making it extremely simple to adapt to changes on all supported chains.
Hackathon Goals
HackSecret has seen us accomplish the following:
- Building the Blockchain Abstraction Layer
- Bringing 1st class SCRT support to Warp
- Performance and user experience updates to Secret-related features (local node, testing frameworks & utilities, support for the latest secret-cosmwasm version)
Additionally, during the hackathon ***Warp was also used to build a secondary submission for HackSecret 2024. ***
Funding received
- AEZ Boost Hackathon
- XION Abstractathon
Main features of Warp CLI
- Scaffold a new Warp workspace – support for multiple contracts that can communicate with each other;
- Scaffold contracts from templates (empty contract, erc20, erc721, etc)
- Build and compile contracts to WASM using multiple toolchains
- Run a local node for testing purposes with a single command
- Test your contracts locally with Mocha and TypeScript in a local sandbox environment
- Write deployment scripts for your contracts in an easy to use markup
- Execute deployment scripts with one command on any network
- Scaffold frontend for your workspace
- Effortlessly switch between mainnet, testnet, and local devnet – or even between different chains altogether! You set the rules of how you deploy your code – we just make sure that it works!
Detailed description
*The following description is taken directly from the project repository README. No major changes have been made to it.
Installation
You can build the binary from the main branch of this repo:
cargo install –git https://github.com/archway-warp/warp-cli.git
Alternatively, there’s also a crates.io option
cargo install arch-warp-cli
Usage
Scaffold, build, test, and deploy Archway Network Smart Contracts faster than ever before
Usage: warp <COMMAND>
Commands:
init Initialize a new Warp project
config Configure the Warp workspace
build Build the current workspace
deploy Execute the ‘Auto Deploy’ script for the workspace (see Warp.toml)
frontend Initialize the frontend for the current workspace
new Scaffold a new contract
node [WIP] Start the local validator node test Run the JavaScript
tests from the ‘/tests/’ directory
wasm Wasm commands for interacting with deployed contracts
help Print this message or the help of the given subcommand(s)
Options:
-h, –help Print help
-V, –version Print version
Initialize a new workspace
Use the warp init <WORKSPACE_PATH> –chain <CHAIN> command to create a new Cargo workspace preconfigured for use with the Warp CLI and the public testnet of your <CHAIN> of choiuce.
This command will clone the warp-template repository and perform some basic setup. The workspace is set up to support the following features out of the box:
- Node.JS testing environment with ts-mocha and chai (tests/ directory – run npm i & yarn in there to get all the packages)
- Basic Warp.toml file that manages the project configuration (deployment scripts, testing setup, and more)
- A shared library for easily sharing ExecuteMsg and QueryMsg models of all contracts in the workspace (everything is taken care of by the Warp CLI)
Scaffolding smart contract template
With warp new <CONTRACT_NAME> you can quickly add a new contract to the workspace. The command clones the contract and takes care of all the boilerplate setup for you:
- Adds the msg.rs module to the shared library for easy access by other contracts
- (CURRENTLY IN DEVELOPMENT) Adds an entry to the AutoDeploy script in Warp.toml to prepare your contract for deployment (of course you will most likely need to modify it to get it to work with your contract later on)
Building the Contracts
To build your contracts you can use the warp build command:
Usage: warp build [OPTIONS] Options: -o, –optimized Build for production with ‘workspace-optimizer’ docker image
This is rather straightforward and works as advertised. In addition, some other commands can invoke this one before execution with a -r (rebuild) flag.
Starting a Local Node
ATTENTION: THIS IS STILL NOT FUNCTIONAL IN THE ARCHWAY MODULE – WORK IN PROGRESS
You can quickly start up a new development node using the localsecret image using the warp node command. This one is still only partially tested, but it is being used internally to allow the test subcommand to work.
Testing your Smart Contracts
If you’ve ever worked with EVM chains and Hardhat, or Solana with Anchor Framework, you will probably find this command to be quite familiar. warp test allows you to run a full testing suite, and, subsequently execute integration and end-to-end tests for your contracts with Node.JS.
Run the JavaScript tests from the ‘/tests/’ directory Usage: warp test [OPTIONS] Options: -r, –rebuild Rebuild the contracts before running tests -s, –skip-environment Don’t start a new instance of localsecret for this testing session
Additionally, while I’m not great at TypeScript, I am also providing a small utility module (tests/src/utils/archway.ts) for making writing your tests as hastle-free as possible. Currently, the utility module contains the following utility functions:
- getConstantineConnection() – Returns a connection to the LCD API of a testnet node
- getGenesisWallets() – Returns an array of pre-loaded genesis wallets available in LocalSecret (you don’t need to remember or look up the mnemonics)
- storeAndInitContract() – A shorthand for uploading your wasm contract to the chain and making an instance of it. Useful for when you only need one instance of a given contract ever in your tests.
- requestFaucetCoinsConstantine – a quick helper function to get some test tokens on theConstantine-2 network.
Deploying your contracts
This is the most complex command available in this CLI tool in terms of the sheer amount of customizability. It interfaces with the local chain CLI installation and config to publish your smart contract to mainnet or testnet.
The warp deploy command uses the autodeploy script defined in the Warp.toml file. The deployment steps are executed in order from top to bottom, and scripts down in the queue can reference addresses of contracts that came before them. This is a feature I needed the most in my own project, as I don’t exactly enjoy TypeScript and it is the main reason for the creation of Warp CLI.
Deployment scripts can reference a previous contract in two ways, depending on the need:
- #_contract – Contract’s Code ID
- $_contract – Contract’s address
Furthermore, the following keywords are implemented:
- $account_id – the deployer account address
Example AutoDeploy Script
The following script will deploy three contracts to the network using the deployer account (secretcli keys show deployer). The first script specifies only the owner parameter, while the other two depend on the deployer account as well as each other:
[autodeploy] account_id = ‘deployer’ # The account to use for deployment
make_labels_unique = true # Append the labels with pseudo-random numbers
[[autodeploy.steps]]
id = ‘$_acl’ # Internal id for use in `init_msg` parameters of later contracts
contract = ‘artifacts/acl.wasm’ # Path to the compiled file
init_msg = ‘{ “default_role”: “CALLER”, “owner”: “$account_id” }’ # `$account_id` will be parsed into the actual secret address of the deployer wallet
label = ‘Dapp: ACL’
coins = ” # Optional: Attach a deposit to the Instantiate call
migrate_msg = ‘{}’
[[autodeploy.steps]]
id = ‘$_system’
contract = ‘artifacts/system_manager.wasm’
init_msg = ‘{ “acl”: “$_acl”, “owner”: “$account_id” }’
label = ‘Dapp: System Manager’
migrate_msg = ‘{}’
[[autodeploy.steps]]
id = ‘$_factory’ contract = ‘artifacts/factory.wasm’
init_msg = ‘{ “acl”: “$_acl”, “system”: “$_system”, “owner”: “$account_id” }’
label = ‘Dapp: Factory’
migrate_msg = ‘{}’
Frontend Integration
It is currently possible to scaffold a simple frontend for a project if targetting the xion chain. Similar behavior will be added for archway and any future chains.
Warp frontend.