Skip to content

Instantly share code, notes, and snippets.

@niponchi
Created April 30, 2019 16:03
Show Gist options
  • Save niponchi/732303b3acd5c86ea3ff9548969814ca to your computer and use it in GitHub Desktop.
Save niponchi/732303b3acd5c86ea3ff9548969814ca to your computer and use it in GitHub Desktop.
const distributeXlm = async (masterAccount, amount, ...walletAccounts) => {
console.log('distribute xlm')
const transferFunc = async (master, destinationPublic, asset, amount) => {
console.log('transfer', asset.code)
let account = await server.loadAccount(destinationPublic)
let transaction = new TransactionBuilder(account, { fee: 100 })
.addOperation(
Operation.payment({
source: master.publicKey(),
amount: `${amount}`,
asset: asset,
destination: destinationPublic,
})
)
.addOperation(
Operation.payment({
source: master.publicKey(),
amount: `${2*0.00001}`,
asset: asset,
destination: destinationPublic,
})
)
.addMemo(Memo.text(`${Date.now()}`))
.setTimeout(TimeoutInfinite)
.build()
transaction.sign(master)
return server.submitTransaction(transaction)
}
txs = walletAccounts.map(w => transferFunc(masterAccount, w.publicKey(), Asset.native(), amount))
await Promise.all(txs)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment