Compiling a Contract
Last updated
Was this helpful?
Last updated
Was this helpful?
Within this section, our objective is to retrieve the code for a sample contract and transform it into a wasm binary executable.
Before you proceed, ensure that you have installed the necessary dependencies as detailed in the "" guide.
To get started, initiate the download of the repository. The contract we'll be compiling is the nameservice contract.
Clone the following repository:
In this section, we will go over how to compile using Cargo.
Execute the following command to compile the contract:
After the compilation process, you should find the file target/wasm32-unknown-unknown/release/cw_nameservice.wasm generated. Its size is roughly 1.9 MB, indicating that it's a release build but hasn't undergone the removal of all redundant code yet. To deploy the contract on-chain, optimization is necessary. Refer to the Optimized Compilation"section below for guidance on optimizing a contract.
In order to minimize gas costs, it is essential to minimize the binary size, resulting in more cost-effective deployment and reduced fees for every interaction. Fortunately, there are available tools to aid in this process. These optimization tools generate reproducible builds of CosmWasm smart contracts, ensuring that third parties can verify the contract's contents as claimed.
Executing the following command should yield an optimized contract suitable for storage on the blockchain:
Navigate to the project root and run the following command:
By running this command, the .wasm file will undergo optimization, resulting in an optimized .wasm file located in the artifacts directory. If you have multiple contracts in the workspace append the name of the specific project you want built.