Polar: Introduction & milestone 1 overview

Arufa Research
4 min readAug 17, 2021

Polar is development framework for building secret contracts. The aim of the project is to make Secret contracts development process simple, efficient and scalable. User can focus on logic of secret contract and not much about further steps in development. It will facilitate features such as initiating project repo from contract templates, easy compilation of contracts, deployment and contract testing framework. Imagine it as npm/yarn for your secret contracts development.

Currently in order to develop secret smart contract or to build a secret DApp consisting of multiple smart contracts, a developer has to setup the contract repository and the environment manually (consisting of understanding and executing multiple commands) which consumes time and effort. Popular blockchains such as Ethereum has Truffle/Hardhat for the very same purposes and Polar would serve the same purpose for Secret Network.

The milestone work which includes the following has been completed and can be seen on the GitHub repository of polar:

Polar init

While creating a project in nodejs, a user usually does not write the boilerplate code but is generated using npm init, similarly a user generates boilerplate code for a React app using create-react-app. Similar is the job of polar init which produces a boilerplate code using which a user can develop secret contracts.

In order to get started, install polar:

  • Using Yarn: yarn global add secret-polar
  • Using NPM: npm install -g secret-polar

Note: Make sure npm/yarn bin directory is in your PATH variable.

Now, doing a polar init <project name> would create a directory with name <project name> inside current working directory and this directory would have the boilerplate code for you to get started easily. The structure of the boiler plate is as follows:

  • artifacts: Generated compiled files .wasm and .json.
  • contracts: Rust files for secret contract logic.
  • scripts: JS/TS scripts to deploy/test/debug the contracts.
  • test: Test scripts in JS/TS.
  • polar.config.js: config file used by polar for the current project.

How init works is that when init is called, the boiler plate code is picked from polar package and copied to the current working directory. This works fine for now but can’t scale well for future needs. We’ll later move the boiler plate code to a separate repository and this repository will hold multiple boiler plate codes for each of the templates provided to the user. We could have a template for multiple smart contracts code, swap contracts code or a multisig contract code.

Polar compile

Now that you have written your contract logic and want to debug it or compile it to .wasm file to later deploy to a network, you can do so using polar compile command.

This will generate the contracts’ .wasm compiled files in artifacts/contracts/ directory and there would be one .wasm file for each of the contract present in contracts/ directory.

When a user runs this command, polar starts compiling contracts sequentially and user can see the progress in the logs emitted by polar. If a contract has a compilation error, that error would be in the logs and these logs can be used to debug the contract’s Rust code.

If a user compiles the same code that was compiled just before it, then polar can detect that the code hasn’t changed since the last compilation and would not compile again and tell the user that there is no new change. If the rust compiler installed on the user’s machine is old and can’t be used to compile or there is a toolchain missing, then polar will notify the user about it and would also tell the version required for the same.

A user can also selectively compile contracts by providing path of contracts after polar compile. For example, there are 3 contracts inside contracts/ directory which are contracts\contract_1, contracts\contract_2, contracts\contract_3 and now the user only wants to compile the first one, then the user can use command polar compile contracts/contract_1.

The way polar compile works is that it calls the required rust compiler with certain flags and parameters to compile the .wasm contracts. Since, the structure of code is already defined by polar init , it’s easy for polar to know where the contracts’ code is located and where to store the output files to, user just needs to be the project directory. For handling same code being compiled again, polar keeps track of a code hash in the cache directory and when polar compile is called, it generates the code hash and compares it with the previous one. If the code hashes are same, then polar does not compile the code.

polar.config.js

This js file is used by polar as it’s project config file. User can modify the behavior of polar for the given project by modifying it’s polar.config.js file. This config file comes included in the boiler plate code and has some default values when generated, such as secret network mainnet and testnet configs, testing mocha timeout. The init and compile commands does not use this config file, there would be few commands in future that’ll make use of this config file while executing such as polar run <script> or polar test.

PS: If you like the project or want to follow any updates, checkout https://twitter.com/ArufaResearch and https://github.com/arufa-research.

--

--