Tezos Domains Wrapper

Tezos Domains is a distributed, open and extensible naming system using the Tezos blockchain.

The Tezos Domains Polywrapper allows you to search for registered Tezos domain names across Tezos testnets and mainnet. The network to search on is detected from the TLD you add, i.e. .tez for mainnet and e.g. .gra or .han for testnets.

Demo app, powered by Tezos Domains Polywrapper: https://blockwatch-cc.github.io/polywrap-tezos-demo/polydomains/

Code repo: https://github.com/blockwatch-cc/polywrap-tezos/tree/main/tezos/tezos-domains

Wrapper

Select one of the various Tezos networks, i.e. testnet or mainnet.

enum Network {
  custom
  mainnet
  ghostnet
  jakartanet
}

Custom Connection

Paste custom connection parameters.

type CustomConnection {
  connection: Tezos_Connection!
  contractAddress: String!
}

Queries

Import Plugins

Import response types from the common/schema.graphql to be used in the query GraphQL.

#import { Query, Connection } into Tezos from "w3://ens/tezos.web3api.eth" 
#import { Network, CustomConnection, DomainInfo } from "../common/schema.graphql"

Resolve Address

Type to resolve address to domain record.

resolveAddress(
    network: Network!
    address: String!
    custom: CustomConnection
 ): DomainInfo

Resolve Domain

Type is to resolve a valid domain name.

resolveDomain(
    network: Network!
    domain: String!
    custom: CustomConnection
 ): DomainInfo

Mutations

Import Plugins

Import methods and types from w3://ens/tezos.web3api.eth, w3://ens/tezosDomainsPlugin.web3api.eth and common/schema.graphql to be used in the mutation schemas.

#import { Connection, Mutation, Query, SendParams } into Tezos from "w3://ens/tezos.web3api.eth"
#import { Query } into TezosDomainsPlugin from "w3://ens/tezosDomainsPlugin.web3api.eth"
#import { Network, CustomConnection } from "../common/schema.graphql"

Fragments (Reusable Types)

Commit Params

type CommitParams {
  # domain name
  label: String!
  # address of owner
  owner: String!
  # Random number
  nonce: UInt32!
}

Buy Params

type BuyParams {
  # domain name
  label: String!
  # address of owner
  owner: String!
  # address of domain
  address: String!
  # Random number
  nonce: UInt32!
  # Duration of domain
  duration: UInt32!
  # metadata of domain
  # Stringified JSON
  data: String!
}

Send Params

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

Mutation

Commit

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

Buy

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

Creating a Web3 client with Tezos Domains plugin support

import { Web3ApiClient } from "@web3api/client-js"
import { tezosDomainsPlugin } from "@web3api/tezos-domains-plugin-js"

export const client = new Web3ApiClient({
    plugins: [{
        uri: "w3://ens/tezos-domains.web3api.eth",
        plugin: tezosDomainsPlugin({
            connections: {
                granadanet: {
                    provider: "https://rpc.granada.tzstats.com",
                    supportedTLDs: ['gra']
                },
                hangzhounet: {
                    provider: "https://rpc.hangzhou.tzstats.com",
                    supportedTLDs: ['han']
                },
                mainnet: {
                    provider: "https://rpc.tzstats.com",
                    supportedTLDs: ['tez']
                }
            },
            defaultNetwork: "mainnet"
        })
    }]
})

A function to resolve a Tezos Domain via Polywrap + GraphQL

const uri = 'w3://ens/tezos-domains.web3api.eth'
export const resolveDomainRecords = async (connection, domain) => {
    return client.query({
        uri,
        query: 
        `query {
	    resolveDomainRecords(connection: $connection, domain: "${domain}" )
        }`,
        variables: {
            connection
        }
    })
}

Wrapper Example

The Tezos Domains plugin can be found in the ./tezos/tezos-domains folder.

Remove these lines of code from the package.json file:

“@web3api/tezos-test-env”: “0.0.1-prealpha.61”, “@web3api/tezos-plugin-js”: “0.0.1-prealpha.61”,

Now, link the wrapper to Tezos-plugin-js and tezos-test-env:

yarn link @web3api/tezos-plugin-js
yarn link @web3api/tezos-test-env

Install the node packages and build plugin-js

yarn
yarn build

Running Tests

The e2e tests can be found in the src/tests/e2e folder. Run the e2e tests as follows:

yarn test

Project Structure

Mutations

Can be found in the ./src/mutation folder containing the index.ts file which is the AssemblyScript mutation logic and schema.graphql file which contains the graphql schemas for the functions in the mutation's index file.

export function callContractMethodAndConfirmation(input: Input_callContractMethodAndConfirmation):
return Tezos_Mutation.callContractMethodAndConfirmation({
    address: input.address,
    method: input.method,
    args: input.args,
    connection: input.connection,
    confirmations: input.confirmations,
    interval: input.interval,
    timeout: input.timeout
})
}						}

Queries

Queries are implemented in the ./src/query folder.

export function callContractMethodAndConfirmation(input: Input_callContractMethodAndConfirmation):
return Tezos_Mutation.callContractMethodAndConfirmation({
    address: input.address,
    method: input.method,
    args: input.args,
    connection: input.connection,
    confirmations: input.confirmations,
    interval: input.interval,
    timeout: input.timeout
})
}

export function getTransferEstimate(input: Input_getTransferEstimate): Tezos_EstimateResult {
    return Tezos_Query.getTransferEstimate({
        connection: input.connection,
        params: input.params
    });
}

Tests

To test the query and mutation functions, e2e tests are available.

it("should check the balance of a valid address", async () => {
    const response = await client.query < {
        getBalance: string
    } > ({
        uri: ensUri,
        query: 
        `query {
	    getBalance(address: $address)
	}`,
        variables: {
            address: accounts[0].address
        }
    })
    expect(response.errors).toBeUndefined()
    expect(response.data).toBeDefined()
    expect(response.data?.getBalance).toBeDefined()
    expect(response.data?.getBalance).toBe("2000000000000")
})

Last updated