diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 73824afaf6..0615cdcaa9 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -25,7 +25,7 @@ - [Make a transfer](examples/promise/07_transfer_dots/README.md) - [Display system events](examples/promise/08_system_events/README.md)( - [Transaction with events](examples/promise/09_transfer_events/README.md) - - [Upgrade with upgradeKey](examples/promise/10_upgrade_chain/README.md) + - [Upgrade via sudo](examples/promise/10_upgrade_chain/README.md) diff --git a/docs/examples/promise/01_simple_connect/package.json b/docs/examples/promise/01_simple_connect/package.json index 5694a21d42..d5e2f5283a 100644 --- a/docs/examples/promise/01_simple_connect/package.json +++ b/docs/examples/promise/01_simple_connect/package.json @@ -11,8 +11,8 @@ }, "dependencies": { - "@polkadot/api": "^0.37.6", - "@polkadot/rpc-provider": "^0.37.6" + "@polkadot/api": "^0.38.6", + "@polkadot/rpc-provider": "^0.38.6" }, "devDependencies": { "rimraf": "^2.6.2" diff --git a/docs/examples/promise/02_listen_to_blocks/package.json b/docs/examples/promise/02_listen_to_blocks/package.json index 88319b921f..614d535ba6 100644 --- a/docs/examples/promise/02_listen_to_blocks/package.json +++ b/docs/examples/promise/02_listen_to_blocks/package.json @@ -10,7 +10,7 @@ "start": "node index.js" }, "dependencies": { - "@polkadot/api": "^0.37.6" + "@polkadot/api": "^0.38.6" }, "devDependencies": { "rimraf": "^2.6.2" diff --git a/docs/examples/promise/03_listen_to_balance_change/package.json b/docs/examples/promise/03_listen_to_balance_change/package.json index 7d765c3bfc..f832cf9f3a 100644 --- a/docs/examples/promise/03_listen_to_balance_change/package.json +++ b/docs/examples/promise/03_listen_to_balance_change/package.json @@ -10,7 +10,7 @@ "start": "node index.js" }, "dependencies": { - "@polkadot/api": "^0.37.6" + "@polkadot/api": "^0.38.6" }, "devDependencies": { "rimraf": "^2.6.2" diff --git a/docs/examples/promise/05_read_storage/package.json b/docs/examples/promise/05_read_storage/package.json index a4de014356..5ab6e26688 100644 --- a/docs/examples/promise/05_read_storage/package.json +++ b/docs/examples/promise/05_read_storage/package.json @@ -10,7 +10,7 @@ "start": "node index.js" }, "dependencies": { - "@polkadot/api": "^0.37.6" + "@polkadot/api": "^0.38.6" }, "devDependencies": { "rimraf": "^2.6.2" diff --git a/docs/examples/promise/07_transfer_dots/package.json b/docs/examples/promise/07_transfer_dots/package.json index 31de2f80b9..ce53b742c2 100644 --- a/docs/examples/promise/07_transfer_dots/package.json +++ b/docs/examples/promise/07_transfer_dots/package.json @@ -10,7 +10,7 @@ "start": "node index.js" }, "dependencies": { - "@polkadot/api": "^0.37.6" + "@polkadot/api": "^0.38.6" }, "devDependencies": { "rimraf": "^2.6.2" diff --git a/docs/examples/promise/08_system_events/package.json b/docs/examples/promise/08_system_events/package.json index ef53706206..33df7e29e5 100644 --- a/docs/examples/promise/08_system_events/package.json +++ b/docs/examples/promise/08_system_events/package.json @@ -10,7 +10,7 @@ "start": "node index.js" }, "dependencies": { - "@polkadot/api": "^0.37.6" + "@polkadot/api": "^0.38.6" }, "devDependencies": { "rimraf": "^2.6.2" diff --git a/docs/examples/promise/09_transfer_events/package.json b/docs/examples/promise/09_transfer_events/package.json index 02850758c7..0e85d8233e 100644 --- a/docs/examples/promise/09_transfer_events/package.json +++ b/docs/examples/promise/09_transfer_events/package.json @@ -10,7 +10,7 @@ "start": "node index.js" }, "dependencies": { - "@polkadot/api": "^0.37.6" + "@polkadot/api": "^0.38.6" }, "devDependencies": { "rimraf": "^2.6.2" diff --git a/docs/examples/promise/10_upgrade_chain/README.md b/docs/examples/promise/10_upgrade_chain/README.md index 934f1c8f63..bd73f4e057 100644 --- a/docs/examples/promise/10_upgrade_chain/README.md +++ b/docs/examples/promise/10_upgrade_chain/README.md @@ -1,5 +1,5 @@ # Chain upgrade -Performs a chain upgrade using the `upgradeKey` module. This may brick your chain, so us it as an educational sample. (use `substrate --dev purge-chain` to remove DB and recover). +Performs a chain upgrade using the `sudo` module. This may brick your chain, so us it as an educational sample. (use `substrate --dev purge-chain` to remove DB and recover). [include](index.js) diff --git a/docs/examples/promise/10_upgrade_chain/index.js b/docs/examples/promise/10_upgrade_chain/index.js index de6c358a1f..be24b3a1fc 100755 --- a/docs/examples/promise/10_upgrade_chain/index.js +++ b/docs/examples/promise/10_upgrade_chain/index.js @@ -8,6 +8,8 @@ const testKeyring = require('@polkadot/keyring/testing'); // utility functions const { compactAddLength, hexToU8a } = require('@polkadot/util'); +const fs = require('fs'); + async function main () { // Initialise the provider to connect to the local node const provider = new WsProvider('ws://127.0.0.1:9944'); @@ -16,29 +18,26 @@ async function main () { const api = await ApiPromise.create(provider); // retrieve the upgrade key from the chain state - const adminId = await api.query.upgradeKey.key(); + 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 exists on the test keyring) + // Alice as the key - and this already exists on the test keyring) const keyring = testKeyring.default(); const adminPair = keyring.getPair(adminId.toString()); - console.log('Upgrading from', adminId.toString(), 'with nonce', adminNonce.toString()); + // retrieve the runtime to upgrade to + const code = fs.readFileSync('./test.wasm').toString('hex'); + const proposal = api.tx.consensus.setCode(`0x${code}`); - // create a properly encoded code array from the hex with length prefix - since we have a - // hex string, we can actuall;y pass it through directly (i.e. `.upgrade('0x...'))` below), - // however here we show how to pass an actual Uint8Array with encoded length - const code = compactAddLength(hexToU8a('0xdeadbeef')); + console.log(`Upgrading from ${adminId} with nonce ${adminNonce}, ${code.length / 2} bytes`); - // preform a chain upgrade, effectively bricking the chain, passing through - // a hex value, although a valid Uint8Array will also work here (in this case - // ensure it has a length prefix added, e.g. compact) - api.tx.upgradeKey - .upgrade(code) + // preform the actual chain upgrade via the sudo module + api.tx.sudo + .sudo(proposal) .sign(adminPair, adminNonce) .send(({ events = [], status, type }) => { console.log('Transaction status:', type); @@ -58,4 +57,7 @@ async function main () { }); } -main().catch(console.error); +main().catch((error) => { + console.error(error); + process.exit(-1); +}); diff --git a/docs/examples/promise/10_upgrade_chain/package.json b/docs/examples/promise/10_upgrade_chain/package.json index 19acc97782..f2a7116dda 100644 --- a/docs/examples/promise/10_upgrade_chain/package.json +++ b/docs/examples/promise/10_upgrade_chain/package.json @@ -10,7 +10,7 @@ "start": "node index.js" }, "dependencies": { - "@polkadot/api": "^0.37.6" + "@polkadot/api": "^0.38.6" }, "devDependencies": { "rimraf": "^2.6.2" diff --git a/docs/examples/promise/10_upgrade_chain/test.wasm b/docs/examples/promise/10_upgrade_chain/test.wasm new file mode 100755 index 0000000000..9355d95f36 Binary files /dev/null and b/docs/examples/promise/10_upgrade_chain/test.wasm differ