Unverified Commit 7d330a60 authored by Michael Müller's avatar Michael Müller Committed by GitHub
Browse files

Update to new `cargo-contract` cli (#575)

* Update to new cargo-contract cli commands

* Fail `build-all` if one of the individual builds fails

* Improve text

* Remove mentions of new .contract file

* Revert "Remove mentions of new .contract file"

This reverts commit a3c959ac.

* Improve readme text
parent 2100fa7c
Pipeline #115822 passed with stages
in 28 minutes and 48 seconds
......@@ -59,7 +59,8 @@ We have [a demonstration testnet](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F
You can request some tokens to play with from our [Faucet](https://riot.im/app/#/room/#canvas_faucet:matrix.parity.io) and deploy your contracts via the [Canvas UI](https://paritytech.github.io/canvas-ui/#/upload).
The [Canvas UI](https://paritytech.github.io/canvas-ui/#/upload) can also be used to deploy your contract to e.g. a Substrate chain which you run locally and execute calls there.
If you want a quickstart you can use our [canvas-node](https://github.com/paritytech/canvas-node#note) project ‒ a simple Substrate blockchain which is configured to include the `contracts` pallet (see [How it Works](#how-it-works) for more).
If you want a quickstart you can use our [canvas-node](https://github.com/paritytech/canvas-node#note) project.
It's a simple Substrate blockchain which is configured to include the Substrate module for smart contract functionality ‒ the `contracts` pallet (see [How it Works](#how-it-works) for more).
## Usage
......@@ -86,10 +87,11 @@ The `lib.rs` contains our hello world contract ‒ the `Flipper`, which we expla
In order to build the contract just execute these commmands in the `flipper` folder:
```
cargo contract build && cargo contract generate-metadata
cargo contract build
```
As a result you'll get a file `target/flipper.wasm` and `target/metadata.json`. Those need to be used when deploying the contract.
As a result you'll get a file `target/flipper.wasm` file, a `metadata.json` file and a `<contract-name>.contract` file in the `target` folder of your contract.
The `.contract` file combines the Wasm and metadata into one file and needs to be used when deploying the contract.
## Hello, World! ‒ The Flipper
......@@ -152,7 +154,7 @@ mod flipper {
}
```
Place this code in the `./lib.rs` file of your flipper contract and run `cargo contract build && cargo contract generate-metadata` to build your first ink! smart contract example.
Place this code in the `./lib.rs` file of your flipper contract and run `cargo contract build` to build your first ink! smart contract example.
## Examples
......@@ -168,7 +170,7 @@ Some of the most interesting ones:
To build a single example navigate to the root of the example and run:
```
cargo contract build && cargo contract generate-metadata
cargo contract build
```
You should now have an optimized `<contract-name>.wasm` file and a `metadata.json` file in the `target` folder of the contract.
......@@ -178,11 +180,12 @@ For further information, please have a look at the [Play with It](#play-with-it)
## How it Works
* Substrate's [Framework for Runtime Aggregation of Modularised Entities (FRAME)](https://substrate.dev/docs/en/next/conceptual/runtime/frame) contains the `contracts` pallet,
which implements an API for typical functions smart contracts need (storage, querying information about account, …).
* Substrate's [Framework for Runtime Aggregation of Modularised Entities (FRAME)](https://substrate.dev/docs/en/next/conceptual/runtime/frame) contains
a module which implements an API for typical functions smart contracts need (storage, querying information about accounts, …).
This module is called the `contracts` pallet,
* The `contracts` pallet requires smart contracts to be uploaded to the blockchain as a Wasm blob.
* ink! is a smart contract language which targets the API exposed by `contracts`.
Hence ink! smart contracts are compiled to Wasm.
Hence ink! contracts are compiled to Wasm.
* When executing `cargo contract build` an additional file `metadata.json` is created.
It contains information about e.g. what methods the contract provides for others to call.
......
......@@ -20,11 +20,8 @@ To build a single example and generate the contracts Wasm file, navigate to the
`cargo contract build`
To generate the contract metadata (a.k.a. the contract ABI), run the following command:
`cargo contract generate-metadata`
You should now have an optimized `<contract-name>.wasm` file and an `metadata.json` file in the `target` folder of your contract.
You should now have an optimized `<contract-name>.wasm` file, a `metadata.json` file and a `<contract-name>.contract` file in the `target` folder of your contract.
The `.contract` file combines the Wasm and metadata into one file and can be used for deployment.
## License
......
......@@ -13,10 +13,11 @@ In order to test this bundle of smart contracts you need to do the following:
1. Compile all dependencies of the Delegator smart contract using the `./build-all.sh` script.
As usual you will receive their respective Wasm blobs in their respective `target` folders.
1. Go to the delegator directory (root of the example) and run `cargo contract generate-metadata`
in order to generate the ABI file for the Delegator smart contract.
Note: You won't need an ABI file for the other smart contracts since we won't operate on them
using the Polkadot UI.
For the delegator (the root of the example) you will additionally get the smart contract as
`delegator.contract` in the `target` folder. This file contains the contracts ABI (i.e.
metadata) bundled together with its Wasm blob.
Note: You won't need a `.contract` file for the other smart contracts `adder`, `subber` and
`accumulator`, since we won't operate on them using the Polkadot UI.
1. Put the Wasm blobs of Accumulator, Adder, Subber and the Delegator on the chain via `put_code` command.
While doing so note down their respective code hashes that you can inspect by extracting this information
out from the signalling events upon putting the code on the chain.
......
#!/usr/bin/env bash
pushd accumulator && cargo +nightly contract build && popd &&
pushd adder && cargo +nightly contract build && popd &&
pushd subber && cargo +nightly contract build && popd &&
set -eu
pushd accumulator && cargo +nightly contract build --generate code-only && popd &&
pushd adder && cargo +nightly contract build --generate code-only && popd &&
pushd subber && cargo +nightly contract build --generate code-only && popd &&
cargo +nightly contract build
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment