Skip to content

Instantly share code, notes, and snippets.

@pinheadmz
Created May 18, 2022 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinheadmz/e5fbe0217e2c587efad18fcf26046ecd to your computer and use it in GitHub Desktop.
Save pinheadmz/e5fbe0217e2c587efad18fcf26046ecd to your computer and use it in GitHub Desktop.
'use strict';
const {NodeClient} = require('hs-client');
const {Address, Network} = require('hsd');
const network = Network.get('main');
if (process.argv.length !== 3)
throw new Error('Usage:\n node transfer-address.js <NAME>');
const name = process.argv[2];
const nodeOptions = {
network: network.type,
port: network.rpcPort
};
const nodeClient = new NodeClient(nodeOptions);
(async () => {
await nodeClient.open();
const {info} = await nodeClient.execute('getnameinfo', [name]);
const {covenant} = await nodeClient.getCoin(
info.owner.hash,
info.owner.index
);
if (covenant.action !== 'TRANSFER')
throw new Error('Name is not being transferred.');
const version = parseInt(covenant.items[2]);
const data = Buffer.from(covenant.items[3], 'hex');
const addr = Address.fromProgram(version, data);
console.log(addr.toString(network));
await nodeClient.close();
process.exit(0);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment