Contract Transcode

Contains utilities for encoding smart contract calls to SCALE.

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

Example

```rust use transcode::ContractMessageTranscoder;

fn main() { let metadata_path = "/path/to/metadata.json";

let metadata = load_metadata(&metadata_path.into())?;
let transcoder = ContractMessageTranscoder::new(&metadata);

let constructor = "new";
let args = ["foo", "bar"];
let data = transcoder.encode(&constructor, &args).unwrap();

println!("Encoded constructor data {:?}", data);

}

fn loadmetadata(path: &Path) -> anyhow::Result { let file = File::open(&path).expect("Failed to open metadata file"); let metadata: ContractMetadata = serdejson::fromreader(file).expect("Failed to deserialize metadata file"); let inkmetadata = serdejson::fromvalue(serde_json::Value::Object(metadata.abi)) .expect("Failed to deserialize ink project metadata");

if let ink_metadata::MetadataVersioned::V3(ink_project) = ink_metadata {
    Ok(ink_project)
} else {
    Err(anyhow!("Unsupported ink metadata version. Expected V3"))
}

}

```