Skip to content

Smart contracts for tracking carbon emissions in the steel industry. Prototype only, not production ready, not audited yet.

License

Notifications You must be signed in to change notification settings

paritytech/co2-passport

Repository files navigation

Non-Fungible Assets For Tracking CO2 Emissions

This smart contract is for tracking carbon emissions of steel. It is written in ink!, a Rust based smart contract language for Substrate based blockchains.

Contract Overview

This contract supports the following operations:

  • Updating contract
  • Blasting an Asset - creating a new Asset with the CO2 Emissions required
  • Adding additional CO2 Emissions to an Asset
  • Transferring an Asset to a different account. Additional C02 Emissions always added
  • Pausing an Asset to prevent transferring or adding new CO2 Emissions. This is a prerequisite to splitting an Asset
  • Splitting an Asset into child Assets. The common reasons is due to actions like steel cutting
  • Querying details about an Asset
  • Querying the full parent tree of a child Asset. This allows for calculating the total CO2 Emissions

Local development setup

Rust and Cargo

Follow the instruction to install Rust and Cargo.

Cargo clippy linter

Follow the instruction to install clippy.

ink! smart contract tools

Follow the instruction to install ink! smart contract tools.

pre-commit

Follow the instruction to install pre-commit tool.

Install the git hook script

pre-commit install

Local Deployment

Contracts Node

In a separated terminal start the Contracts Node:

substrate-contracts-node

Smart Contract

Build Smart Contract:

cargo contract build --release

Smart Contracts UI

  1. Go to Contracts UI.
  2. Select Upload a new contract.
  3. In Upload and Instantiate window:
    • Set contract name like InfinityAsset.
    • Upload contract details -> select target/ink/asset_co2_emissions.contract from the Smart Contract repository.
    • Press Next button.
    • Press Next button.
    • Press Upload and Instantiate button.
  4. Interact with the Smart Contract.

Live Deployment

There are several places where an ink! contract can be deployed! The ink! documentation has an up-to-date list of where to deploy.

Deploying on Contracts on Rococo

This example will be using Contracts on Rococo to deploy a contract.

  1. Get testnet tokens using this faucet.
  2. Build the contract.
cargo contract build --release
  1. Navigate to the Contracts page at contracts-ui.substrate.io.
  2. Ensure "Contracts (Rococo)" is selected.
  3. Select Upload a new contract.
  4. Upload the built contract found at ./target/ink/asset_co2_emissions.contract. This file contains the contract Wasm bytecode and the metadata.
  5. Click Next, modify the limits as desired. The default values are generally sufficient.
  6. Click Next and finally Upload and instantiate.
  7. The contract can now be used.

The documentation found here provides more details and also instructions on how deploy contracts using cargo contract.

Development

Below you can find some base commands, for more information check official documentation.

Format code

cargo +nightly fmt

Run clippy linter

cargo +nightly clippy --all-features

Check that smart contracts build to WASM

cargo contract check

Testing

cargo test --features e2e-tests

Build smart contracts

cargo contract build --release

Run pre-commit

pre-commit run --all-files

CI Jobs

This repository contains predefined GitHub actions for quality assurance.

GitHub runners

  • Linux -> ubuntu-20.04

Jobs

  • Formatting check -> cargo +nightly fmt --check
  • Linter check -> cargo +nightly clippy --all-features
  • Building smart contracts -> cargo contract build
  • Testing smart contracts -> cargo test --features e2e-tests
  • Integration tests -> yarn test --exit

Integration Tests

The integration tests for this project are written using Cucumber.js.

The tests are defined in features/. The following files describe the tests and user stories using Gherkin Syntax:

The test implementations are found in:

Running Integration Tests

From the project root

  1. Install dependencies:
yarn
  1. Start substrate-contracts-node using v0.24.0
substrate-contracts-node --dev
  1. Run the tests:
yarn test --exit

About

Smart contracts for tracking carbon emissions in the steel industry. Prototype only, not production ready, not audited yet.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Contributors 4

  •  
  •  
  •  
  •