Skip to content

Instantly share code, notes, and snippets.

@JesseAbram
Created June 10, 2019 19:14
Show Gist options
  • Save JesseAbram/920a5316c4606f705c289d30c659ec73 to your computer and use it in GitHub Desktop.
Save JesseAbram/920a5316c4606f705c289d30c659ec73 to your computer and use it in GitHub Desktop.
const { ApiPromise } = require("@polkadot/api");
const WsProvider = require("@polkadot/rpc-provider").WsProvider;
const { Keyring } = require("@polkadot/keyring");
exports.createTransaction = async (to, wallet, token) => {
const provider = new WsProvider(token.networkUrl);
const keyring = new Keyring({ type: wallet.keyType });
const pk = keyring.addFromMnemonic(wallet.privateKey);
const api = await ApiPromise.create(provider);
const txn = await api.tx.balances.transfer(to, token.maxSupplyAllowed).signAndSend(pk);
if (provider.isConnected()) provider.disconnect()
return txn
}
exports.sendTransaction = async (txn, options) => {
return Object.assign(options, {
hash: txn.toHex(),
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment