Commit a4df58aa authored by Amaury Martiny's avatar Amaury Martiny
Browse files

feat: balanceTransfer

parent b9a1cc8a
......@@ -7,6 +7,7 @@
"main": "lib/index.js",
"repository": "https://github.com/amaurymartiny/polkadotjs-wrapper",
"scripts": {
"lint": "tsc --noEmit && eslint . --ext ts",
"test": "jest"
},
"dependencies": {
......
import metadataRpc from '@polkadot/metadata/Metadata/v9/static';
import { balanceTransfer } from './balanceTransfer';
describe('balanceTransfer', () => {
it('should work', () => {
const call = balanceTransfer(
metadataRpc,
'Fy2rsYCoowQBtuFXqLE65ehAY9T6KWcGiNCQAyPDCkfpm4s',
12
);
expect(call).toBe(
'0x0600ff96074594cccf1cd185fa8a72ceaeefd86648f8d45514f3ce33c31bdd07e4655d30'
);
});
});
import Metadata from '@polkadot/metadata';
import { TypeRegistry } from '@polkadot/types';
/**
* Construct a balance transfer transaction offline
*
* @param metadataRpc - The SCALE-encoded metadata, as a hex string. Can be
* retrieved via the RPC all `state_getMetadata`
* @param to - The recipient of the transfer
* @param amount - The amount to send
*/
export function balanceTransfer(
metadataRpc: string,
to: string,
amount: number
): string {
const registry = new TypeRegistry();
const metadata = new Metadata(registry, metadataRpc);
return metadata.tx.balances.transfer(to, amount).toHex();
}
import { deriveAddress } from './deriveAddress';
describe('generateKeypair', () => {
describe('deriveAddress', () => {
it('should work', () => {
const address = deriveAddress(
'0x96074594cccf1cd185fa8a72ceaeefd86648f8d45514f3ce33c31bdd07e4655d'
......
export * from './balanceTransfer';
export * from './deriveAddress';
export * from './generateKeypair';
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment