Created
July 11, 2019 23:17
-
-
Save wangshijun/f67882198ba85f9ae957bcb841d71ec5 to your computer and use it in GitHub Desktop.
forge recipers: transfer token from moderator to another account on
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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