set-sudo-as-screening-auth.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* global api, hashing, keyring, types, util, joy, window */
  2. // run this script with:
  3. // yarn workspace api-scripts script set-sudo-as-screening-auth
  4. //
  5. // or copy and paste the code into the pioneer javascript toolbox at:
  6. // https://testnet.joystream.org/#/js
  7. //
  8. // requires nicaea release+
  9. const script = async ({ api, keyring }) => {
  10. const sudoAddress = (await api.query.sudo.key()).toString()
  11. let sudo
  12. if (typeof window === 'undefined') {
  13. // In node, get the keyPair if the keyring was provided
  14. sudo = keyring.getPair(sudoAddress)
  15. } else {
  16. // Pioneer: let the UI Signer handle it
  17. sudo = sudoAddress
  18. }
  19. const tx = api.tx.members.setScreeningAuthority(sudoAddress)
  20. const nonce = (await api.query.system.account(sudoAddress)).nonce
  21. const sudoTx = api.tx.sudo.sudo(tx)
  22. const signed = sudoTx.sign(sudo, { nonce })
  23. await signed.send()
  24. console.log(`sent tx with nonce: ${nonce.toNumber()}, tx hash: ${signed.hash}`)
  25. }
  26. if (typeof module === 'undefined') {
  27. // Pioneer js-toolbox
  28. script({ api, hashing, keyring, types, util, joy })
  29. } else {
  30. // Node
  31. module.exports = script
  32. }