Remove the nonce when using signAndSend (promise examples) (#648)

* Remove the nonce when using signAndSend

* Update descriptions
This commit is contained in:
Jaco Greeff
2019-01-29 19:47:25 +01:00
committed by GitHub
parent 273f1260e4
commit 4fa8ee085c
2 changed files with 4 additions and 11 deletions
@@ -16,16 +16,12 @@ async function main () {
// Instantiate the API
const api = await ApiPromise.create();
// Retrieve the nonce for Alice, to be used to sign the transaction
const aliceNonce = await api.query.system.accountNonce(alice.address());
// Create a extrinsic, transferring 12345 units to Bob. We can also create,
// sign and send in one operation (as per the samples in the Api documentation),
// here we split it out for the sake of readability
// Create a extrinsic, transferring 12345 units to Bob
const transfer = api.tx.balances.transfer(BOB_ADDR, 12345);
// Sign and send the transaction using our account. Send the transaction and retrieve the resulting Hash
// Sign and send the transaction using our account
transfer.signAndSend(alice, ({ status, type }) => {
// retrieve the hash once we are finalised
if (type === 'Finalised') {
console.log(`Successful transfer of 12345 from Alice to Bob with hash ${status.asFinalised.toHex()}`);
} else {
@@ -17,9 +17,6 @@ async function main () {
// retrieve the upgrade key from the chain state
const adminId = await api.query.sudo.key();
// get the nonce for the admin key
const adminNonce = await api.query.system.accountNonce(adminId);
// find the actual keypair in the keyring (if this is an changed value, the key
// needs to be added to the keyring before - this assumes we have defaults, i.e.
// Alice as the key - and this already exists on the test keyring)
@@ -30,7 +27,7 @@ async function main () {
const code = fs.readFileSync('./test.wasm').toString('hex');
const proposal = api.tx.consensus.setCode(`0x${code}`);
console.log(`Upgrading from ${adminId} with nonce ${adminNonce}, ${code.length / 2} bytes`);
console.log(`Upgrading from ${adminId}, ${code.length / 2} bytes`);
// preform the actual chain upgrade via the sudo module
api.tx.sudo