Creating Client Instance
Once you have installed the Polywrap JS client, the next step is to create a new Polywrap client instance.
Project Structure
services/
├── client.js # Web3APIClient Integration
├── query.js # Query function calls
└── mutation.js # Mutation function calls
Client JS
.services/client.js
# Import client-js
import { Web3ApiClient } from '@web3api/client-js';
# Import tezos-plugin-js
import { tezosPlugin } from "@web3api/tezos-plugin-js"
# Export the wrapper URI where in this case QmY... is the IPFS Hash
export const TEZOS_WRAPPER_URI = 'w3://ipfs/QmYSJ3dHJuNWygFtBThKHNB7Na1mSq7uSCLYE4991CQkZY'
export const TEZOS_PLUGIN_JS = 'w3://ens/tezos.web3api.eth'
export const TezosConnections = {
ghostnet: {
provider: "https://rpc.ghost.tzstats.com",
supportedTLDs: ['ith']
},
mainnet: {
provider: "https://rpc.tzstats.com",
supportedTLDs: ['tez']
},
}
export const client = new Web3ApiClient({
plugins: [
{
uri: TEZOS_PLUGIN_JS,
plugin: tezosPlugin({
networks: {
mainnet: {
provider: "https://rpc.tzstats.com"
},
ghostnet: {
provider: "https://rpc.ghost.tzstats.com",
}
},
defaultNetwork: "ghostnet"
})
}
]
})
Queries
.services/query.js
import { client } from './client'
import { TEZOS_WRAPPER_URI } from './client'
export const listTokenPairs = async (network) => {
return client.query({
uri: TEZOS_WRAPPER_URI,
query: `
query {
listTokenPairs(
network: ghostnet
)
}
`,
variables: {
network,
}
})
}
Mutations
.services/mutation.js
import { client, TEZOS_PLUGIN_JS, TEZOS_WRAPPER_URI } from "./client"
export const connectTempleWallet = (network) => {
return client.query({
uri: TEZOS_PLUGIN_JS,
query: `
mutation {
connectTempleWallet(
appName: "yourappname",
network: $network,
connection: $connection
)
},
`,
variables: {
network,
connection: {
network
}
}
})
}
export const addOperator = (network, payload) => {
return client.query({
uri: TEZOS_QUIPUSWAP_WRAPPER_URI,
query: `
mutation {
addOperator (
network: ghostnet,
params: $params
)
},
`,
variables: {
params: payload
}
})
}
Last updated