Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function transfer (keyRingFrom, addressTo, amount) {
const accountIndex = await getAccountIndex(keyRingFrom.address());
console.log(`Current accountIndex: ${accountIndex}`);
// encode the call for signing
const message = encodeExtrinsic(
keyRingFrom.publicKey(),
accountIndex,
extrinsics.staking.public.transfer,
[addressTo, amount]
);
// get the signature
const signature = keyRingFrom.sign(message);
// encode the extrinsic for submission, adding the length (prefix) and the
// signature (postfix)Rödl
const encoded = encodeLength(
// When working with publicKeys, the prefix is 0xff for poc-2+
new Uint8Array([0xff]),
message,
signature
);
return api.author.submitExtrinsic(encoded);
async function transfer (keyRingFrom, addressTo, amount) {
const nextAccountIndex = await getAccountIndex(keyRingFrom.address());
// encode the call for signing
const encoded = encodeExtrinsic(
keyRingFrom,
nextAccountIndex,
extrinsics.staking.public.transfer,
[addressTo, amount]
);
await api.author.submitExtrinsic(encoded)
.catch(e => console.log);
}