README
Polkadot.js integration for Blackprint
This module gives you an ability to use Polkadot.js's APIs with Blackprint.
Examples
For more updated example, please go to /example folder and import it with Blackprint Editor.
Listening to new block (JSON)
Open this example on Blackprint Editor.
You can also import this JSON into Blackprint Editor.
{"_":{"moduleJS":["https://cdn.jsdelivr.net/npm/@blackprint/nodes-polkadot.js@0.2/dist/nodes-polkadotjs.mjs","https://cdn.jsdelivr.net/npm/@blackprint/nodes@0.3.1/dist/nodes-console.mjs","https://cdn.jsdelivr.net/npm/@blackprint/nodes@0.3.1/dist/nodes-decoration.mjs"]},"Polkadot.js/Connection/WebSocket":[{"i":0,"x":52,"y":51,"data":{"rpcURL":"wss://rpc.shibuya.astar.network"},"output":{"API":[{"i":4,"name":"API"}]}},{"i":1,"x":52,"y":244,"data":{"rpcURL":"wss://ws.test.azero.dev"},"output":{"API":[{"i":5,"name":"API"}]}}],"Console/Log":[{"i":2,"x":656,"y":158},{"i":3,"x":654,"y":262}],"Polkadot.js/Events/Blocks":[{"i":4,"x":406,"y":69,"output":{"Number":[{"i":2,"name":"Any"}]}},{"i":5,"x":408,"y":262,"output":{"Number":[{"i":3,"name":"Any"}]}}],"Decoration/Text/Notes":[{"i":6,"x":658,"y":69,"data":{"value":"You can also CTRL + Right click on a port to get suggested node"}}]}
Distributable files
All files inside src
folder will be bundled into 3 distributable file. Some file is optional to be loaded on the target environment.
// all .js files
- dist/nodes-polkadotjs.mjs // For browser, Node.js, and Deno (required)
// all .sf files
- dist/nodes-polkadotjs.sf.mjs // For browser only (required)
- dist/nodes-polkadotjs.sf.css // For browser only (optional)
Directory structure
Configuration file can be changed from ./blackprint.config.js
.
The src
directory structure is arranged like below:
File path | Blackprint Node path |
---|---|
./src/Account/Transfer.js |
Polkadot.js/Account/Transfer |
./src/Connection/WebSocket.js |
Polkadot.js/Connection/WebSocket |
With the above structure, you can easily find the nodes on Blackprint Editor like below:
Development
You will need to clone this repository and install the required dependencies.
$ npm install
Watch changes and run a local server
By running local server you can ask Blackprint Editor to connect into it to enjoy hot reload.
If you only want to do a testing, please skip this step.
$ npm start
Build and minify
Bundle every files and minify it into 3 distributable file.
$ npm run build-prod
Running Test
- We will use Jest to do the testing for Browser and Node.js
- Before running this test, make sure you have build this module
- Westend's testnet will be used (My mnemonic is stored on GitHub Action's secrets)
- If you're going to test from your environment, please rename
.env.example
to.env
and edit it - Address for ChainId: 42
- Wallet A:
5CPKqqEXE3YHKProqt5e6o8Lw9xBSdpf5Ex44U5WjL82yKPj
- Wallet B:
5CdiLQpHyeJJsdgP5azER3dtBmgRTNhYQhLxRdmBmRqXQRGH
- Wallet A:
$ npm test
Import this nodes from URL
Please specify the version to avoid breaking changes.
Blackprint.loadModuleFromURL([
'https://cdn.jsdelivr.net/npm/@blackprint/nodes-polkadot.js@0.2/dist/nodes-polkadotjs.mjs'
], {
// Turn this on if you want to load ".sf.js" and ".sf.css" for browser
loadBrowserInterface: true // set to "false" for Node.js/Deno
});
Development URL
You can use this link to load unpublished nodes that still under development on GitHub.
https://cdn.jsdelivr.net/gh/Blackprint/nodes-polkadot.js@dist/nodes-polkadotjs.mjs?1
Please append
/url-here?random-number
if your browser still using the cached files
License
MIT