Browse Source

Proposal 127, KPI 6.9: fixing community scripts - added informative README

singulart 3 years ago
parent
commit
a984d8e15d
2 changed files with 57 additions and 28 deletions
  1. 55 26
      joystream-api/README.md
  2. 2 2
      joystream-api/src/examples/get-events-and-extrinsics.ts

+ 55 - 26
joystream-api/README.md

@@ -3,46 +3,75 @@
 Repo with examples on how to use the @joystream/types package along with @polkadot/api to communicate with a joystream full node.
 
 
-## Examples
+## Building the code
 
 ```
 yarn && yarn build
-yarn run status
 ```
 
-## Example code
+In case you have a compilation error saying:
 
-```javascript
-import { registerJoystreamTypes } from '@joystream/types';
-import { ApiPromise, WsProvider } from '@polkadot/api';
+```
+node_modules/@joystream/types/content-working-group/index.d.ts:3:22 - error TS2614: Module '"../common"' has no exported member 'Credential'. Did you mean to use 'import Credential from "../common"' instead?
+
+3 import { OptionText, Credential, SlashingTerms } from '../common';
+                       ~~~~~~~~~~
+Found 1 error.
+```
+
+Open the file ```node_modules/@joystream/types/content-working-group/index.d.ts``` in a text editor and remove the failing import, so that the line looks as follows: ``` import { OptionText, SlashingTerms } from '../common'; ```
 
-async function main () {
-  // Initialise the provider to connect to the local node
-  const provider = new WsProvider('ws://127.0.0.1:9944');
+Save the changes and re-run ```yarn && yarn build``` again, the build should work fine. 
 
-  // Register types before creating the API
-  registerJoystreamTypes();
 
-  // Create the API and wait until ready
-  const api = await ApiPromise.create({ provider });
+### Scripts
 
-  // Retrieve the chain & node information information via rpc calls
-  const [chain, nodeName, nodeVersion] = await Promise.all([
-    api.rpc.system.chain(),
-    api.rpc.system.name(),
-    api.rpc.system.version()
-  ]);
+#### general.js
 
-  console.log(`Chain ${chain} using ${nodeName} v${nodeVersion}`);
-}
+Ideal for newcomers. Contains the very basic APIs usage examples: get the last blockchain finalized block, get total coin issuance. 
+Also shows how to iterate the events inside a given block.
 
-main();
+```
+node lib/examples/general.js
 ```
 
-### Scripts
+#### get-media-change.js
 
-You can run scripts that are found in the [./scripts/](./scripts) folder:
+Shows how to work with Substrate events and Extrinsics to get the information about Joystream media uploads. 
 
-```sh
-yarn script example
 ```
+node lib/curators/get-media-change.js
+```
+
+#### council.js
+
+Shows how to use ```councilElection```, ```minting```, ```council``` APIs. 
+
+```
+node lib/examples/council.js
+```
+
+#### get-events-and-extrinsics.js
+
+Shows the variety of Substrate event Extrinsic types within a given range of blocks. 
+
+```
+node lib/examples/get-events-and-extrinsics.js
+```
+
+#### working-groups.js
+
+Shows how to use a set of APIs related to Joystream working groups: ```storageWorkingGroup```, ```recurringRewards```, ```contentDirectoryWorkingGroup```. 
+
+```
+node lib/examples/working-groups.js
+```
+
+#### proposals.js
+
+Shows how to use a APIs related to Joystream DAO proposals ```proposalsEngine```, ```staking```, ```members```. 
+
+```
+node lib/examples/proposals.js
+```
+

+ 2 - 2
joystream-api/src/examples/get-events-and-extrinsics.ts

@@ -15,8 +15,8 @@ async function main() {
 
     // get all extrinsic and event types in a range of blocks (only works for last 200 blocks unless you are querying an archival node)
     // will take a loooong time if you check too many blocks :)
-    const firstBlock = 1
-    const lastBlock = 10000
+    const firstBlock = 800000
+    const lastBlock = 801000
     const eventTypes:string[] = []
     const extrinsicTypes: string[] = []
     for (let blockHeight=firstBlock; blockHeight<lastBlock; blockHeight++) {