Writing a Wrapper

The first step to adding functionality to your new wrapper is to update the mutation schema by defining the methods you'd like users to query in GraphQL.

Here's an example of method and custom data types of our Tezos Domains wrapper that are added in your ./src/mutation/schema.graphql schema file:

type Mutation {
 ...

type CommitParams {
  label: String!
  owner: String!
  nonce: UInt32!
}

type BuyParams {
  label: String!
  owner: String!
  address: String!
  nonce: UInt32!
  duration: UInt32!
  data: String!
}

type SendParams {
  amount: UInt32
  source: String
  fee: UInt32
  gasLimit: UInt32
  storageLimit: UInt32
  mutez: Boolean
}

type Mutation {
  commit (
    network: Network!
    params: CommitParams!
    sendParams: SendParams
    custom: CustomConnection
  ): String!

  buy (
    network: Network!
    params: BuyParams!
    sendParams: SendParams
    custom: CustomConnection
  ): String!
}

Import New Types

In your src/mutation/index.ts file, import the new types that you defined:

import {
 Input_commit,
 Tezos_Mutation,
 Input_buy,
 TezosDomainsPlugin_Query,
} from "./w3"

# Importing codes that can be used in both queries and mutations 
import { getConnection, getSendParams } from "../common/utils";

# Importing a query function into mutation
import { encodeCommitment } from "../query";

Although these new types will not yet exist, they'll be generated in the ./src/mutation/w3/* folder after building via yarn.

Implement Mutation Method

Now you can implement the mutation method by adding the function to the bottom of your ./src/mutation/index.ts file. Example:

export function buy(input: Input_buy): string {
 const label = TezosDomainsPlugin_Query.char2Bytes({
   text: input.params.label
 });
 const address = getConnection(input.network, "Buy", input.custom);
 const hash = Tezos_Mutation.walletContractCallMethod({
   address: address.contractAddress,
   method: "buy",
   args: '["' +
     label + '", "' +
     input.params.duration.toString() + '", "' + 
     input.params.owner + '", "' +
     input.params.address + '", ' +
     input.params.data + ', "' +
     input.params.nonce.toString() +
   '"]',
   params: getSendParams(input.sendParams, address.contractAddress),
   connection: address.connection
 })
 return hash;
}

Last updated