Browse Source

api-examples: transferTest script

Mokhtar Naamani 4 years ago
parent
commit
bfa03059c4
2 changed files with 36 additions and 0 deletions
  1. 1 0
      api-examples/scripts/index.js
  2. 35 0
      api-examples/scripts/transfer.js

+ 1 - 0
api-examples/scripts/index.js

@@ -6,5 +6,6 @@ exportedScripts.example = require('./example.js')
 exportedScripts.exportDataDirectory = require('./export-data-directory.js')
 exportedScripts.injectDataObjects = require('./inject-data-objects.js')
 exportedScripts.listDataDirectory = require('./list-data-directory.js')
+exportedScripts.testTransfer = require('./transfer.js')
 
 module.exports = exportedScripts

+ 35 - 0
api-examples/scripts/transfer.js

@@ -0,0 +1,35 @@
+/* global api, hashing, keyring, types, util, window */
+
+// run this script with:
+// yarn script injectDataObjects
+//
+// or copy and paste the code into the pioneer javascript toolbox at:
+// https://testnet.joystream.org/#/js
+//
+// requires nicaea release+
+
+const script = async ({ api, keyring, types, joy }) => {
+  const sudoAddress = (await api.query.sudo.key()).toString()
+  let sudo
+  if (typeof window === 'undefined') {
+    // In node, get the keyPair if the keyring was provided
+    sudo = keyring.getPair(sudoAddress)
+  } else {
+    // Pioneer: let the UI Signer handle it
+    sudo = sudoAddress
+  }
+
+  const nonce = (await api.query.system.account(sudoAddress)).nonce
+
+  const transfer = api.tx.balances.transfer(sudoAddress, 100)
+  console.log(transfer)
+  await transfer.signAndSend(sudo)
+}
+
+if (typeof module === 'undefined') {
+  // Pioneer js-toolbox
+  script({ api, hashing, keyring, types, util })
+} else {
+  // Node
+  module.exports = script
+}