2019-10-27 09:21:36 -07:00
|
|
|
const Bnc = require('@binance-chain/javascript-sdk')
|
|
|
|
|
|
|
|
const { delay } = require('./wait')
|
|
|
|
|
|
|
|
const { FOREIGN_URL, FOREIGN_ASSET } = process.env
|
|
|
|
|
2019-11-01 11:43:25 -07:00
|
|
|
module.exports = async function main(privateKey) {
|
2019-10-27 09:21:36 -07:00
|
|
|
const client = new Bnc(FOREIGN_URL)
|
|
|
|
client.chooseNetwork('testnet')
|
|
|
|
|
|
|
|
await client.setPrivateKey(privateKey)
|
|
|
|
|
|
|
|
await client.initChain()
|
|
|
|
const from = client.getClientKeyAddress()
|
|
|
|
|
|
|
|
await delay(1000)
|
|
|
|
|
|
|
|
return {
|
2019-11-01 11:43:25 -07:00
|
|
|
async transfer(to, tokens, bnbs) {
|
2019-10-27 09:21:36 -07:00
|
|
|
const outputs = [{
|
|
|
|
to,
|
|
|
|
coins: []
|
|
|
|
}]
|
|
|
|
if (tokens) {
|
|
|
|
outputs[0].coins.push({
|
|
|
|
denom: FOREIGN_ASSET,
|
|
|
|
amount: tokens
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (bnbs) {
|
|
|
|
outputs[0].coins.push({
|
|
|
|
denom: 'BNB',
|
|
|
|
amount: bnbs
|
|
|
|
})
|
|
|
|
}
|
|
|
|
await client.multiSend(from, outputs, 'funding')
|
|
|
|
},
|
2019-11-01 11:43:25 -07:00
|
|
|
async exchange(to, value) {
|
2019-11-14 06:44:08 -08:00
|
|
|
await client.transfer(from, to, value.toString(), FOREIGN_ASSET, '')
|
2019-10-27 09:21:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|