Skip to main content


Metadata is a kind of interface map that helps to transform a set of bytes into an understandable structure and indicates the function this structure is intended for. Metadata determines how all incoming and outgoing data will be encoded/decoded.

Metadata allows dApp’s parts - the smart-contract and the client side (JavaScript), to understand each other and exchange data.

To describe metadata interface use gmeta crate:

use gmeta::{InOut, Metadata};

pub struct ProgramMetadata;

// Be sure to describe all the types.
// But if any of the endpoints is missing in your program, you can use ();
// as indicated in the case of `type Signal`.

impl Metadata for ProgramMetadata {
type Init = InOut<MessageInitIn, MessageInitOut>;
type Handle = InOut<MessageIn, MessageOut>;
type Others = InOut<MessageAsyncIn, Option<u8>>;
type Reply = InOut<String, Vec<u16>>;
type Signal = ();
type State = Vec<Wallet>;

As we can see, metadata enables you to determine the expected data at the input/output for the contract at each endpoint. Where:

  • Init - describes incoming/outgoing types for init() function.
  • Handle - describes incoming/outgoing types for handle() function.
  • Others - describes incoming/outgoing types for main() function in case of asyncronius interaction.
  • Reply - describes incoming/outgoing types of message performed using the handle_reply function.
  • Signal - describes only the outgoing type from the program while processing the system signal.
  • State - describes the types for the queried State

Genarate metadata

To generate metadata, the following file in the root of your project folder is required:

// Where ProgramMetadata is your metadata structure

use meta_io::ProgramMetadata;

fn main() {

As a result of the smart-contract compilation, a meta.txt file will be generated. This metadata file can be used in the UI applications that will interact with this smart-contract. The file’s content looks like a hex string:


Verify metadata

To make it possible to verify metadata for a program, you can use the metahash() function. It allows verifying metadata on-chain.

// It returns the Hash of metadata.
// .metahash is generating automatically while you are using
extern "C" fn metahash() {
let metahash: [u8; 32] = include!("../.metahash");
msg::reply(metahash, 0).expect("Failed to share metahash");