diff --git a/docs/cookbook/blocks.md b/docs/cookbook/blocks.md index 79eb33b978..645dccd2c4 100644 --- a/docs/cookbook/blocks.md +++ b/docs/cookbook/blocks.md @@ -12,8 +12,9 @@ const blockHash = await this.api.rpc.chain.getBlockHash(blockNumber); // returns SignedBlock const signedBlock = await this.api.rpc.chain.getBlock(blockHash); -// the hash for the block, always via header (Hash -> toHex()) - will be the same as -// blockHash above (also available on any header retrieved, subscription or once-off) +// the hash for the block, always via header (Hash -> toHex()) - will be +// the same as blockHash above (also available on any header retrieved, +// subscription or once-off) console.log(signedBlock.header.hash.toHex()); // the hash for each extrinsic in the block diff --git a/docs/cookbook/storage.md b/docs/cookbook/storage.md index 7bc822ae2f..e7dcc9590d 100644 --- a/docs/cookbook/storage.md +++ b/docs/cookbook/storage.md @@ -4,7 +4,7 @@ Here you will find snippets for working with storage. ## How do I check for storage existence? -In the metadata, for each storage item a fallback is provided. This means that when an entry does not exist, the fallback (which is the default value for the type) will be provided. This means, that querying for a non-existent key (unless an option), will ield a value - +In the metadata, for each storage item a fallback is provided. This means that when an entry does not exist, the fallback (which is the default value for the type) will be provided. This means, that querying for a non-existent key (unless an option), will yield a value - ```js // retrieve Option diff --git a/docs/cookbook/tx.md b/docs/cookbook/tx.md index 17a953fc67..dff66a4e12 100644 --- a/docs/cookbook/tx.md +++ b/docs/cookbook/tx.md @@ -7,14 +7,19 @@ A blockchain is no fun if you are not submitting transactions. Or at least if so In addition to the `signAndSend` helper on transactions, `.paymentInfo` (with the exact same parameters) are also exposed. Using the same sender, it applies a dummy signature to the transaction and then gets the fee estimation via RPC. ```js -// estimate the fees as RuntimeDispatchInfo, using the signer (either address or locked/unlocked keypair) -// (When overrides are applied, e.g. nonce, the format would be `paymentInfo(sender, { nonce })`) +// estimate the fees as RuntimeDispatchInfo, using the signer (either +// address or locked/unlocked keypair) (When overrides are applied, e.g +// nonce, the format would be `paymentInfo(sender, { nonce })`) const info = await api.tx.balances .transfer(recipient, 123) .paymentInfo(sender); -// log relevant info, partialFee is Balance, estmated for current conditions -console.log(`class=${class.toString()}, weight=${weight.toString()}, partialFee=${partialFee.toHuman()}`); +// log relevant info, partialFee is Balance, estimated for current +console.log(` + class=${class.toString()}, + weight=${weight.toString()}, + partialFee=${partialFee.toHuman()} +`); ``` ## How do I get the decoded enum for an ExtrinsicFailed event? @@ -28,18 +33,22 @@ api.tx.balances if (status.isInBlock || status.isFinalized) { events // find/filter for failed events - .filter(({ section, method }) => section === 'system' && method === 'ExtrinsicFailed') - // we know that data for system.ExtrinsicFailed is (DispatchError, DispatchInfo) - .forEach(({ data: [dispatchError, dispatchInfo] }) => { - - if (dispatchError.isModule) { + .filter(({ section, method }) => + section === 'system' && + method === 'ExtrinsicFailed' + ) + // we know that data for system.ExtrinsicFailed is + // (DispatchError, DispatchInfo) + .forEach(({ data: [error, info] }) => { + if (error.isModule) { // for module errors, we have the section indexed, lookup - const { documentation, name, section } = this.api.registry.findMetaError(dispatchError.asModule); + const decoded = api.registry.findMetaError(error.asModule); + const { documentation, method, section } = decoded; - console.log(`${section}.${name}: ${documentation.join(' ')}`); + console.log(`${section}.${method}: ${documentation.join(' ')}`); } else { // Other, CannotLookup, BadOrigin, no extra info - console.log(dispatchError.toString()); + console.log(error.toString()); } }); }