Skip to content

Instantly share code, notes, and snippets.

@wangshijun wangshijun/index.js
Created Jul 11, 2019

Embed
What would you like to do?
forge recipers: transfer token from moderator to another account on
/* eslint-disable no-console */
const base64 = require('base64-url');
const { fromSecretKey, fromRandom } = require('@arcblock/forge-wallet');
const { bytesToHex, isHexStrict, fromTokenToUnit } = require('@arcblock/forge-util');
const GraphqlClient = require('@arcblock/graphql-client');
const endpoint = process.env.FORGE_API_HOST || 'http://127.0.0.1:8210'; // testnet
const client = new GraphqlClient(`${endpoint}/api`);
function ensureModeratorSecretKey() {
const sk = process.env.FORGE_MODERATOR_SK;
if (!sk) {
console.error('please set FORGE_MODERATOR_SK to continue');
process.exit(1);
}
if (isHexStrict(sk)) {
return sk;
}
// debug('detected base64 moderator sk', base64.unescape(sk));
return bytesToHex(Buffer.from(base64.unescape(sk), 'base64'));
}
(async () => {
const sk = ensureModeratorSecretKey();
const moderator = fromSecretKey(sk);
const receiver = fromRandom();
// Declare the receiver
const hash = await client.sendDeclareTx({
tx: {
itx: { moniker: 'receiver' },
},
wallet: receiver,
});
console.log(`receiver declare hash ${hash}`);
// Transfer to receiver
const hash2 = await client.sendTransferTx({
tx: {
itx: {
to: receiver.toAddress(),
value: fromTokenToUnit(10000),
},
},
wallet: moderator,
});
console.log(`receiver transfer hash ${hash2}`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.