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.
- Non-Fungible Assets with CO2 Emissions tracking
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
Follow the instruction to install Rust and Cargo.
Follow the instruction to install clippy
.
Follow the instruction to install ink!
smart contract tools.
Follow the instruction to install pre-commit
tool.
pre-commit install
In a separated terminal start the Contracts Node:
substrate-contracts-node
Build Smart Contract:
cargo contract build --release
- Go to Contracts UI.
- Select
Upload a new contract
. - 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.
- Set contract name like
- Interact with the Smart Contract.
There are several places where an ink! contract can be deployed! The ink! documentation has an up-to-date list of where to deploy.
This example will be using Contracts on Rococo to deploy a contract.
- Get testnet tokens using this faucet.
- Build the contract.
cargo contract build --release
- Navigate to the Contracts page at contracts-ui.substrate.io.
- Ensure "Contracts (Rococo)" is selected.
- Select
Upload a new contract
. - Upload the built contract found at
./target/ink/asset_co2_emissions.contract
. This file contains the contract Wasm bytecode and the metadata. - Click
Next
, modify the limits as desired. The default values are generally sufficient. - Click
Next
and finallyUpload and instantiate
. - The contract can now be used.
The documentation found here provides more details and also instructions on how deploy contracts using cargo contract
.
Below you can find some base commands, for more information check official documentation.
cargo +nightly fmt
cargo +nightly clippy --all-features
cargo contract check
cargo test --features e2e-tests
cargo contract build --release
pre-commit run --all-files
This repository contains predefined GitHub actions for quality assurance.
- Linux ->
ubuntu-20.04
- 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
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:
- features/support/steps.js: the test definitions using
Cucumber.js
. - features/support/world.js: the environment class used by the tests that manages interactions with Substrate and the contract.
From the project root
- Install dependencies:
yarn
- Start
substrate-contracts-node
using v0.24.0
substrate-contracts-node --dev
- Run the tests:
yarn test --exit