How to use Ancon Protocol Hybrid Smart Contracts
- Clone Ancon Protocol contracts repo. https://github.com/anconprotocol/contracts
You will see there are 4 files in contracts/metadata/src example :
- sdk.rs — contains host wrappers
- lib.rs — main entry
- host.rs — host entry
- contract.rs — here is where graphql dag contracts are implemented
Eg metadata retrieval and mutation looks like this:
Before being able to work with smart contracts, create a DID accounts. This account will be anchored in a blockchain and stored as DAG in ipfs. Ancon Protocol relies on DID to manage L2 and cross chain ownership of data, ie non fungible tokens.
Creating and enrolling a DID will have a cost once the platform is enabled.
To upload a rust wasm smart contract, sign a payload message with your did account private key and attached message with signature. You can follow the deployer-contract.ts example in playground folder 📂.
You will get a cid which is where the smart contract is stored.
Similar to deployer-contract.ts, there is a execute-contract.ts, this will send a JSON-RPC request with the following properties:
- to — the smart contract cid
- from — the sender DID cid address (later releases will support both cid and did)
- data — graph ql query
- signature — payload signature
If everything goes well, convert the results to plain text from hex and parse with JSON.parse.
In the next post we’ll go through the proof implementation using vector commitments with ICS23 and using L1 consensus to validate proofs.