const endpoint = arguments[0];
const seed = arguments[1];
const amount = arguments[2];
const api = await ApiPromise.create({ provider: new pjs.api.WsProvider(endpoint) });
await utilCrypto.cryptoWaitReady();
const k = new keyring.Keyring({ type: "sr25519" });
const signer = k.addFromUri(seed);
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
const randomAmount = amount || Math.floor((Math.random() * 100000) + 1);
const transferAllowDeath = api.tx.balances.transferAllowDeath(BOB, randomAmount);
return new Promise(async (resolve, _reject) => {
const unsub = await transferAllowDeath.signAndSend(signer, { nonce: -1 }, ({ events = [], status }) => {
if (status.isInBlock) {
console.log('Successful transfer of ' + randomAmount + ' with hash ' + status.asInBlock.toHex());
return resolve(randomAmount);
} else {
console.log('Status of transfer: ' + status.type);
}
events.forEach(({ phase, event: { data, method, section } }) => {
console.log(phase.toString() + ' : ' + section + '.' + method + ' ' + data.toString());
});
});
});