Table of Contents
This is an Aleph Zero smart contract that we created to help us understand and experiment with ink and paintbrush. It's a contract that lets users turn a light switch on and off.
- Initialise with a on_fee, off_payment, minimum amount of seconds before a user can turn off the light.
- Allow user to turn on light for a fee.
- Allow user to turn off light and receive a payment. A certain amount of seconds must have passed before user can turn off light.
- Enable admin to change the admin, on_fee, off_payment and minimum_on_time_in_seconds.
To get a local copy up and running follow these simple example steps.
- Open brush required that I use rust nightly but building the contract required stable.
- A pre-requisite for compiling smart contracts is to have a stable Rust version and Cargo installed. Here's an installation guide.
- The first tool we will be installing is cargo-contract, a CLI tool for helping setting up and managing WebAssembly smart contracts written with ink!.
- Setup developer blockchain and Docker: https://docs.scrt.network/dev/developing-secret-contracts.html#personal-secret-network-for-secret-contract-development
By default, cargo-contract builds the contract in debug mode. This means that the contract will e.g. print statements like
ink::env::debug_println!("magic number: {}", value);to the node's console if debugging was enabled on the node (instructions here). To support functionality like this the debug build of a contract includes some heavy-weight logic.
For contracts that are supposed to run in production you should always build the contract with --release:
cargo +stable contract build --releaseThis will ensure that nothing unnecessary is compiled into the Wasm blob, making your contract faster and cheaper to deploy and execute.
The substrate-contracts-node is a simple Substrate blockchain which is configured to include the Substrate module for smart contract functionality – the contracts pallet (see How it Works for more). It's a comfortable option if you want to get a quickstart. Download the binary here.
After successfully installing substrate-contracts-node, you can start a local development chain by running:
substrate-contracts-nodeYou can interact with your node using the Contracts UI. Once you have the webpage open, click on the dropdown selector at the top left corner and choose "Local Node".
Note that blocks are only created when you execute a function in substrate-contracts-node, so trigger a another function first if a function depends on a time delay.
- https://realtakahashi-work.medium.com/substrate-ink-how-to-define-own-struct-%E7%8B%AC%E8%87%AA%E6%A7%8B%E9%80%A0%E4%BD%93%E3%81%AE%E5%AE%A3%E8%A8%80%E6%96%B9%E6%B3%95-8f4893089ba4
- https://github.com/paritytech/ink-examples/blob/main/contract-transfer/lib.rs
- https://github.com/paritytech/ink
- https://learn.brushfam.io/docs/OpenBrush/smart-contracts/ownable
- https://github.com/Brushfam/openbrush-contracts/blob/main/lang/src/test_utils.rs#L39
- https://github.com/Brushfam/openbrush-contracts/blob/main/contracts/src/access/ownable/mod.rs
- https://github.com/Supercolony-net/openbrush-contracts/blob/96b556536a9806cb2a0db7a6159a412754ceba9b/contracts/src/traits/errors/psp22.rs#L100
- https://paritytech.github.io/ink/ink_env/test/index.html
- https://use.ink/basics/contract-testing/
- https://use.ink/examples/smart-contracts
- https://use.ink/getting-started/building-your-contract
- https://substrate.stackexchange.com/questions/1174/why-is-it-a-bad-idea-to-use-string-in-an-ink-smart-contract