Using Tezos-Domains with Conseiljs to Perform Transfers Easily
By: Pawan Dhanwani
Tags: Tezos, Wallet, Tezos Domains, Blockchain, Tezos India

In this article, we will develop a CLI app that would use Tezos-Domains and Conseiljs to perform the transfer of XTZ.

Why use Tezos-Domains?

Remembering tz1 addresses can be tough hence a project called Tezos-Domains is created to provide a human-readable and especially rememberable address to everyone. It is important to utilize such tech to do operations easily.

Let's get a domain name

Libraries

"@taquito/taquito": "^6.3.5-beta.0", "@tezos-domains/client": "^1.0.0-beta.13", "@tezos-domains/core": "^1.0.0-beta.13", "conseiljs": "^5.0.4", "conseiljs-softsigner": "^5.0.3", "loglevel": "^1.7.0", "node-fetch": "^2.6.1", "readline": "^1.3.0"

Setting up Conseiljs

“tezosNode” is a network-specific.

const conseiljs = require('conseiljs'); const softsigner = require('conseiljs-softsigner'); const fetch = require('node-fetch'); const log = require('loglevel'); const logger = log.getLogger('conseiljs'); logger.setLevel('ERROR',true); conseiljs.registerLogger(logger); conseiljs.registerFetch(fetch); const tezosNode = 'https://carthagenet.smartpy.io';

Setting upTaquito

“rpcProvider” is a network-specific.

const TezosDomainClient = require('@tezos-domains/client'); const Taquito = require('@taquito/taquito'); Taquito.Tezos.setRpcProvider('https://carthagenet.smartpy.io');

Creating “readline” instance

“readline” library is used to fetch users’ inputs from the console.

const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout });

Creating domain name resolver

Domain name resolver helps resolve a domain name to tz1 address which would then be utilized by Conseiljs to perform the transfer.

Change the network type to ‘mainnet’ if you want to perform transactions there.

const DomainNameResolver = new TezosDomainClient.TezosDomainsClient({ network: 'carthagenet', caching: { enabled: true } });

Declaring Keystore

Keystore is the “from” account being used here.

const keystore = { publicKey: 'edpkukocydHK4BwwZUrRmhT4JGNg1wRVqcgnc7hWYYg2YHuLDqQMib', privateKey: 'edskRkWyj8xhpUv8ge1B3hQHGki2AtvFox86AVKbftajP7t6Sd3npdGdAYDdpZvoqbvTn5vi1ytFL58B4RmHN7oeQAEh695C3Y', publicKeyHash: 'tz1a4UNywaxaAfh2LRBP2UugQTeCVcLCn5Sa', seed: '', storeType: conseiljs.KeyStoreType.Fundraiser };

I would suggest you use your own keys.

The Function

We first need to create a Signer that would sign the transfer operation.

Then we create a chain of promises. The first promise would resolve a domain to an address. The second one would take the address and amount passed and perform the transfer and return the operationHash.

const resolveAndTransfer = async (domain,amount) => { const signer = await softsigner.SoftSigner.createSigner(conseiljs.TezosMessageUtils.writeKeyWithHint(keystore.privateKey,'edsk')); DomainNameResolver.resolver.resolve(domain) .then(receiverAddress => { return conseiljs.TezosNodeWriter.sendTransactionOperation(tezosNode,signer,keystore,receiverAddress.address,amount,100000,-1) }) .then( operationResponse => { console.log('Transfer Successfull : ' , operationResponse.operationGroupID); }) .catch(err => { console.log(err); }) }

Taking user input

rl.question('To whom you want to send tez ? ', receiver => { rl.question('How much ? ' , amount => { resolveAndTransfer(receiver , amount); rl.close(); }) })

Works like a charm

Here is the transaction we performed.

You can clone the code and run it from here.