test-transfer.js 956 B

123456789101112131415161718192021222324252627282930313233
  1. /* global api, hashing, keyring, types, util, joy, window */
  2. // run this script with:
  3. // yarn workspace api-scripts script test-transfer
  4. //
  5. // or copy and paste the code into the pioneer javascript toolbox at:
  6. // https://testnet.joystream.org/#/js
  7. //
  8. const script = async ({ api, keyring, userAddress }) => {
  9. const sudoAddress = (await api.query.sudo.key()).toString()
  10. const destination = userAddress || sudoAddress
  11. let sender
  12. if (typeof window === 'undefined') {
  13. // In node, get the keyPair if the keyring was provided
  14. sender = keyring.getPair(destination)
  15. } else {
  16. // Pioneer: let the UI Signer handle it
  17. sender = destination
  18. }
  19. // Send test transfer to self
  20. const transfer = api.tx.balances.transfer(destination, 10)
  21. await transfer.signAndSend(sender)
  22. }
  23. if (typeof module === 'undefined') {
  24. // Pioneer js-toolbox
  25. script({ api, hashing, keyring, types, util, joy })
  26. } else {
  27. // Node
  28. module.exports = script
  29. }