Onchain Metadata

Introduction

Onchain metadata stores metadata as an IPLD Dag Cbor node. This allows the protocol to treat metadata as CID hashes, similar to those in IPFS or Filecoin.

Ancon metadata model is very basic but you can extend it with Links and Verified credentials.

For our use case, we use DIDs for cross chain identities. But it can be specific to your domain model eg Cosmos Bech32 addresses or Ethereum Hex Addresses.

Creating onchain metadata with cosmjs-web3provider

  1. Configure a provider, in this case AnconWeb3Provider

const accounts = await window.ethereum.enable();
this.anconWeb3client = new AnconWeb3Provider(
  'https://ancon.did.pa/evm',
  'ancon',
  'anconprotocol_9000-1',
  9000,
  new ethers.providers.Web3Provider(window.ethereum),
  accounts[0] as string
);

await this.anconWeb3client.connectProvider();

Create a new Metadata message

// Sign and broadcast Cosmos enveloped tx (Keplr) in MsgEthereumTx (uses ancon_sendRawTransaction)
const msg = MsgMetadata.fromPartial({
  creator: this.anconWeb3client.cosmosAccount.address,
  name,
  image: 'http://localhost:8081/someimg.png',
  additionalSources: [],
  links: [],
  owner: `did:ether:9000:${accounts[0]}`,
  description,
});


await this.anconWeb3client.signAndBroadcast(
  msg,
  fee: {
    amount: [
      {
        denom: "aancon",
        amount: "2000",
      },
    ],
    gas: "5000000",
  },
)   

Subscribing to events


// Subscribe to messages
const query = `message.action='Metadata'`;
const c = this.anconWeb3client.tm.subscribeTx(query);
const listener = {
  next: async (log: TxEvent) => {
    // Decode response
    const res = MsgMetadataResponse.decode(log.result.data);
    console.log(res);
  }
}

Last updated