docs: add examples from polkadot

This commit is contained in:
ian.he
2019-04-12 17:40:12 +12:00
parent f103863fdd
commit c14a071b74
59 changed files with 462 additions and 74 deletions
@@ -0,0 +1,5 @@
# Make a simple transfer
This sample shows how to create a transaction to make a transfer from one an account to another.
<<< @/docs/examples/promise/06_make_transfer/index.js
@@ -2,25 +2,21 @@
// Import the API, Keyring and some utility functions
const { ApiPromise } = require('@polkadot/api');
const { Keyring } = require('@polkadot/keyring');
const { stringToU8a } = require('@polkadot/util');
// Important to note that we pad the seed to a length of 32 bytes using ' '
// The underlying seed needs to be exactly 32 bytes in length
const ALICE_SEED = 'Alice'.padEnd(32, ' ');
const BOB_ADDR = '5Gw3s7q4QLkSWwknsiPtjujPv3XM4Trxi5d4PgKMMk3gfGTE';
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
async function main () {
// Create an instance of the keyring
const keyring = new Keyring();
// Add Alice to our keyring (with the known seed for the account)
const alice = keyring.addFromSeed(stringToU8a(ALICE_SEED));
// Instantiate the API
const api = await ApiPromise.create();
// Constuct the keying after the API (crypto has an async init)
const keyring = new Keyring({ type: 'sr25519' });
// Add alice to our keyring with a hard-deived path (empty phrase, so uses dev)
const alice = keyring.addFromUri('//Alice');
// Create a extrinsic, transferring 12345 units to Bob
const transfer = api.tx.balances.transfer(BOB_ADDR, 12345);
const transfer = api.tx.balances.transfer(BOB, 12345);
// Sign and send the transaction using our account
const hash = await transfer.signAndSend(alice);
@@ -10,7 +10,7 @@
"start": "node index.js"
},
"dependencies": {
"@polkadot/api": "^0.45.14"
"@polkadot/api": "^0.53.1"
},
"devDependencies": {
"rimraf": "^2.6.2"