16 releases (3 stable)

Uses new Rust 2021

2.0.0-beta Nov 22, 2022
2.0.0-alpha.3 Sep 22, 2022
1.5.0 Aug 15, 2022
1.4.0 Jun 21, 2022
0.1.0 Oct 13, 2020

#2747 in Magic Beans

Download history 585/week @ 2022-08-12 756/week @ 2022-08-19 1411/week @ 2022-08-26 1164/week @ 2022-09-02 941/week @ 2022-09-09 768/week @ 2022-09-16 777/week @ 2022-09-23 862/week @ 2022-09-30 797/week @ 2022-10-07 919/week @ 2022-10-14 1524/week @ 2022-10-21 1341/week @ 2022-10-28 1460/week @ 2022-11-04 1460/week @ 2022-11-11 1947/week @ 2022-11-18 1330/week @ 2022-11-25

6,459 downloads per month
Used in 5 crates

Apache-2.0

32KB
756 lines

Contract Metadata

Defines types for the extended metadata of smart contracts targeting substrate.

Currently part of cargo-contract, the build tool for smart contracts written in ink!.


lib.rs:

Type definitions for creating and serializing metadata for smart contracts targeting Substrate's contracts pallet.

Example

# use contract_metadata::*;
# use semver::Version;
# use url::Url;
# use serde_json::{Map, Value};

let language = SourceLanguage::new(Language::Ink, Version::new(2, 1, 0));
let compiler = SourceCompiler::new(Compiler::RustC, Version::parse("1.46.0-nightly").unwrap());
let wasm = SourceWasm::new(vec![0u8]);
// Optional information about how the contract was build
let build_info: Map<String, Value> = Map::new();
let source = Source::new(Some(wasm), CodeHash([0u8; 32]), language, compiler, Some(build_info));
let contract = Contract::builder()
    .name("incrementer".to_string())
    .version(Version::new(2, 1, 0))
    .authors(vec!["Parity Technologies <admin@parity.io>".to_string()])
    .description("increment a value".to_string())
    .documentation(Url::parse("http://docs.rs/").unwrap())
    .repository(Url::parse("http://github.com/paritytech/ink/").unwrap())
    .homepage(Url::parse("http://example.com/").unwrap())
    .license("Apache-2.0".to_string())
    .build()
    .unwrap();
// user defined raw json
let user_json: Map<String, Value> = Map::new();
let user = User::new(user_json);
// contract abi raw json generated by contract compilation
let abi_json: Map<String, Value> = Map::new();

let metadata = ContractMetadata::new(source, contract, Some(user), abi_json);

// serialize to json
let json = serde_json::to_value(&metadata).unwrap();

Dependencies

~2.1–3MB
~92K SLoC