I want to send native enjin token on the enjin relay chain from my wallet to another wallet using a js script. I am using @polkadot/api package.
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api';
import "dotenv/config";
async function main() {
const wsProvider = new WsProvider('wss://rpc.relay.blockchain.enjin.io');
const api = await ApiPromise.create({ provider: wsProvider });
const keyring = new Keyring({ type: 'sr25519' })
const PHRASE = process.env.PRIVATE_KEY_RELAYCHAIN;
const newPair = keyring.addFromUri(PHRASE);
const unsub = await api.tx.balances
.transfer('enCxhF3S8ANdQ7dh75yar3ZrXKd9PMDLCHJmvNPSKgm38E5nh', 1)
.signAndSend(newPair, (result) => {
console.log(`Current status is ${result.status}`);
if (result.status.isInBlock) {
console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
} else if (result.status.isFinalized) {
console.log(`Transaction finalized at blockHash ${result.status.asFinalized}`);
unsub();
}
});
}
main().catch(console.error).finally(() => process.exit());
Here is the code snippet coppied mostly from https://polkadot.js.org/docs/api/start/api.tx.subs
Can someone explain what i am doing wrong and how to go about it.