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/

Wrapper

Select one of the various Tezos networks, i.e. testnet or mainnet.
1
enum Network {
2
custom
3
mainnet
4
granadanet
5
hangzhounet
6
}
Copied!

Custom Connection

Paste custom connection parameters.
1
type CustomConnection {
2
connection: Tezos_Connection!
3
contractAddress: String!
4
}
Copied!

Queries

Import Plugins

Import response types from the common/schema.graphql to be used in the query GraphQL.
1
#import { Query, Connection } into Tezos from "w3://ens/tezos.web3api.eth"
2
#import { Network, CustomConnection, DomainInfo } from "../common/schema.graphql"
Copied!

Resolve Address

Type to resolve address to domain record.
1
resolveAddress(
2
network: Network!
3
address: String!
4
custom: CustomConnection
5
): DomainInfo
Copied!

Resolve Domain

Type is to resolve a valid domain name.
1
resolveDomain(
2
network: Network!
3
domain: String!
4
custom: CustomConnection
5
): DomainInfo
Copied!

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.
1
#import { Connection, Mutation, Query, SendParams } into Tezos from "w3://ens/tezos.web3api.eth"
2
#import { Query } into TezosDomainsPlugin from "w3://ens/tezosDomainsPlugin.web3api.eth"
3
#import { Network, CustomConnection } from "../common/schema.graphql"
Copied!

Fragments (Reusable Types)

Commit Params

1
type CommitParams {
2
# domain name
3
label: String!
4
# address of owner
5
owner: String!
6
# Random number
7
nonce: UInt32!
8
}
Copied!

Buy Params

1
type BuyParams {
2
# domain name
3
label: String!
4
# address of owner
5
owner: String!
6
# address of domain
7
address: String!
8
# Random number
9
nonce: UInt32!
10
# Duration of domain
11
duration: UInt32!
12
# metadata of domain
13
# Stringified JSON
14
data: String!
15
}
Copied!

Send Params

1
type SendParams {
2
amount: UInt32
3
source: String
4
fee: UInt32
5
gasLimit: UInt32
6
storageLimit: UInt32
7
mutez: Boolean
8
}
Copied!

Mutation

Commit

1
commit (
2
network: Network!
3
params: CommitParams!
4
sendParams: SendParams
5
custom: CustomConnection
6
): String!
Copied!

Buy

1
buy (
2
network: Network!
3
params: BuyParams!
4
sendParams: SendParams
5
custom: CustomConnection
6
): String!
Copied!

Creating a Web3 client with Tezos Domains plugin support

1
import { Web3ApiClient } from "@web3api/client-js"
2
import { tezosDomainsPlugin } from "@web3api/tezos-domains-plugin-js"
3
4
export const client = new Web3ApiClient({
5
plugins: [{
6
uri: "w3://ens/tezos-domains.web3api.eth",
7
plugin: tezosDomainsPlugin({
8
connections: {
9
granadanet: {
10
provider: "https://rpc.granada.tzstats.com",
11
supportedTLDs: ['gra']
12
},
13
hangzhounet: {
14
provider: "https://rpc.hangzhou.tzstats.com",
15
supportedTLDs: ['han']
16
},
17
mainnet: {
18
provider: "https://rpc.tzstats.com",
19
supportedTLDs: ['tez']
20
}
21
},
22
defaultNetwork: "mainnet"
23
})
24
}]
25
})
Copied!

A function to resolve a Tezos Domain via Polywrap + GraphQL

1
const uri = 'w3://ens/tezos-domains.web3api.eth'
2
export const resolveDomainRecords = async (connection, domain) => {
3
return client.query({
4
uri,
5
query:
6
`query {
7
resolveDomainRecords(connection: $connection, domain: "${domain}" )
8
}`,
9
variables: {
10
connection
11
}
12
})
13
}
Copied!

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:
1
“@web3api/tezos-test-env”:0.0.1-prealpha.61, “@web3api/tezos-plugin-js”:0.0.1-prealpha.61,
Copied!
Now, link the wrapper to Tezos-plugin-js and tezos-test-env:
1
yarn link @web3api/tezos-plugin-js
2
yarn link @web3api/tezos-test-env
Copied!
Install the node packages and build plugin-js
1
yarn
2
yarn build
Copied!

Running Tests

The e2e tests can be found in the src/tests/e2e folder. Run the e2e tests as follows:
1
yarn test
Copied!

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.
1
export function callContractMethodAndConfirmation(input: Input_callContractMethodAndConfirmation):
2
return Tezos_Mutation.callContractMethodAndConfirmation({
3
address: input.address,
4
method: input.method,
5
args: input.args,
6
connection: input.connection,
7
confirmations: input.confirmations,
8
interval: input.interval,
9
timeout: input.timeout
10
})
11
} }
Copied!

Queries

Queries are implemented in the ./src/query folder.
1
export function callContractMethodAndConfirmation(input: Input_callContractMethodAndConfirmation):
2
return Tezos_Mutation.callContractMethodAndConfirmation({
3
address: input.address,
4
method: input.method,
5
args: input.args,
6
connection: input.connection,
7
confirmations: input.confirmations,
8
interval: input.interval,
9
timeout: input.timeout
10
})
11
}
12
13
export function getTransferEstimate(input: Input_getTransferEstimate): Tezos_EstimateResult {
14
return Tezos_Query.getTransferEstimate({
15
connection: input.connection,
16
params: input.params
17
});
18
}
Copied!

Tests

To test the query and mutation functions, e2e tests are available.
1
it("should check the balance of a valid address", async () => {
2
const response = await client.query < {
3
getBalance: string
4
} > ({
5
uri: ensUri,
6
query:
7
`query {
8
getBalance(address: $address)
9
}`,
10
variables: {
11
address: accounts[0].address
12
}
13
})
14
expect(response.errors).toBeUndefined()
15
expect(response.data).toBeDefined()
16
expect(response.data?.getBalance).toBeDefined()
17
expect(response.data?.getBalance).toBe("2000000000000")
18
})
Copied!
Last modified 1mo ago