🐳Docker Verification

Docker verification process

NEAR Protocol Contract Verification Using Docker

This guide outlines the process for verifying NEAR protocol contracts using the official NEAR protocol Docker image.

1. Installing Docker

Before you begin, you need to install the Docker engine on your system. Follow the instructions provided in the Docker Engine Installation Guide.

2. Compilation

Option 1: Using the SourceScan Rust Builder

  • Obtain Builder Script: Visit the SourceScan Contract Builders repository and navigate to rust/builder.sh.

  • Download and Run Script: Clone the repository or download the builder.sh script. Run this script in the root directory of your contract. It will handle Docker container setup and contract building

Script Parameters:

  • -i --image (optional): Specify the Docker image for building. If not provided, the default image used is nearprotocol/contract-builder:latest-amd64.

    • Example: -i nearprotocol/contract-builder:latest-amd64.

  • -r --run (optional): Specify a command to run inside the Docker container. This is useful if you have a specific build script like build.sh.

    • Example: --run contract/.build.sh.

  • Default Behavior: If no parameters are provided, the script will simply launch the Docker container environment, allowing you to manually navigate and run commands as needed.

build.sh

#!/bin/bash

if [ -z "$KEEP_NAMES" ]; then
  export RUSTFLAGS='-C link-arg=-s'
else
  export RUSTFLAGS=''
fi
rustup target add wasm32-unknown-unknown
cargo build --all --target wasm32-unknown-unknown --release

Running the Script:

With Parameters:

Run ./builder.sh -i [image-name] -r [command-to-run] to specify a custom image and/or run a specific script.

Without Parameters:

Run ./builder.sh to enter the container environment. From there:

  1. Navigate to /host in the Docker environment.

  2. Then, go to your contract's folder where Cargo.toml is located.

  3. export RUSTFLAGS='-C link-arg=-s'
    cargo build --target wasm32-unknown-unknown --release

Option 2: Manual Compilation Using Docker

Pulling the Official Docker Image

After installing Docker, you can pull the official NEAR protocol Docker image and mount it using the command below. Make sure to clone the specific repository and choose the specific commit from GitHub. Inside the repository folder, mount the container with the following command:

docker run \
     --mount type=bind,source="$(pwd)",target=/host \
     -i -t nearprotocol/contract-builder:latest-amd64 \
     /bin/bash

Note: This command pulls the latest amd64 image. It should run fine on ARM CPUs under QEMU.

Entering the Docker Environment

  • Access Mounted Folder: After executing the command, enter the Docker environment. Navigate to the mounted folder inside the Docker container at /host using cd /host.

  • Navigate to Contract Folder: Move to the contract folder with cd path/to/contract-folder.

  • Build the Contract: Compile the contract as you normally would. The process may take longer than outside the container. Upon completion, type exit to leave the Docker container. The compiled wasm file will be in the default compilation folder.

3. Verifying Contract Compilation

  • Using code-hash.sh: After building your contract, use the code-hash.sh script from the SourceScan repository to calculate the SHA256 sum in base58 of the wasm binary. This verifies the contract's compilation integrity.

4. Deploying the Contract

  • Deploy wasm File: Use near-cli-rs to deploy the compiled wasm file as you would outside of the container.

5. Verification in BOS App

  • Final Steps: After deployment, go to the BOS app, select the repository, commit, and the Docker verification option. Proceed with the further verification steps.

This guide provides a comprehensive approach to building and verifying NEAR protocol contracts using Docker, ensuring consistency, reliability, and ease of use throughout the process.

Last updated