This guide is complimentary to our previous article on deploying a REM full node. However, if you do not wish to set up a node of your own you can connect to our
wasmql endpoint at
https://rem.eon.llc/wasmql/v1/query and use these files.
This example will be built on Desktop of our local machine, for illustrative purposes only. Because of that, we will be downloading all of the necessary files. Technically, you can build this example directly on your full node by providing relative paths to files below. For reference, here is the official documentation.
During full node build, explained in the previous article, we’ve created a number of directories. For this guide we need to pay particular attention to
Build directory should look something like this:
CMakeCache.txt CPackSourceConfig.cmake chain-server.wasm cmake_install.cmake fill-lmdb legacy-server.wasm token-server.wasm wasm-ql-lmdb wasms_project-prefix
CMakeFiles build.ninja chain_request_schema.json combo-lmdb fill-pg rules.ninja token_request_schema.json wasm-ql-pg
CPackConfig.cmake chain-client.wasm chain_response_schema.json external history-tools token-client.wasm token_response_schema.json wasms
We need to copy two of those files to our local machine:
While src directory should be something like this:
HistoryTools.js fill_pg_plugin.cpp glue.js main.cpp query-config.json state_history.hpp util.hpp wasm_ql_lmdb_plugin.hpp wasm_ql_plugin.hpp
create-init-sql.js fill_pg_plugin.hpp init.sql node_modules query_config.hpp state_history_lmdb.hpp wasm_interface.cpp wasm_ql_pg_plugin.cpp
fill_lmdb_plugin.cpp fill_plugin.cpp lmdb_plugin.cpp pg_plugin.cpp query_config_plugin.cpp state_history_pg.hpp wasm_interface.hpp wasm_ql_pg_plugin.hpp
fill_lmdb_plugin.hpp fill_plugin.hpp lmdb_plugin.hpp pg_plugin.hpp query_config_plugin.hpp test-client.js wasm_ql_lmdb_plugin.cpp wasm_ql_plugin.cpp
The only file we need from here is
How to Download
There are many ways to copy these files but one of the easiest is via
scp or secure copy command. The structure of this command is roughly:
scp username@ip:/path/to/server/file.txt /path/to/local/directory
This command needs to be executed from your local machine, NOT your node instance. If you have an AWS instance with
ssh key access, copying each file to your Desktop is performed like so:
scp firstname.lastname@example.org:/home/ubuntu/history-tools/src/HistoryTools.js ~/Desktopscp email@example.com:/home/ubuntu/history-tools/build/chain-client.wasm ~/Desktopscp firstname.lastname@example.org:/home/ubuntu/history-tools/build/token-client.wasm ~/Desktop
Now that we have everything we need, these three files can be combined in a single
For the sake of formatting, all of the code is within this gist:
If you open this
index.html file in a browser you’ll see an error in console, along the lines of:
Fetch API cannot load file:///Users/you/Desktop/chain-client.wasm. URL scheme must be “http” or “https” for CORS request.
This is the first of a number of issues that are really meant to protect you, the end user. Our browser is not allowing plain html page to have access to the local file system. Lines 6, 23 and 30 are trying to load files and that is prohibited. What we have to do is use a server to serve these files. Any server will do, but one of the easiest is provided by Node.js and NPM. NPM ships with Node.js, if you don’t have it go ahead and install from the link above.
npm install http-server -g and start it from the directory with our
index.html by running
http-server . If you’re strictly following along, we’d issue that command directly from our Desktop.
The server will start with the following output:
Starting up http-server, serving ./
That means we can access our
index.html by visiting one of the ip’s or
You’ll probably see another error that references CORS.
Access to fetch at ‘https://rem.eon.llc/wasmql/v1/query' from origin ‘http://localhost:8080' has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.
The easiest way to solve this issue is by installing a CORS extension for your browser. As always, there are many choices but this is the one we use on Chrome.
This plugin seems to break other websites when enabled so make sure to turn it off when not in use.
Once installed, open the extension and enable cross-origin resource sharing.
You should now see a response from our server.
Note on Official Docs
We’ve added several comments to the
index.html file above. One of the most important ones is for viewing schema structure. Some of the examples listed in official documentation did not work for us, likely because the schema has changed.
// Create a request: get a range of accounts
const request1 = chainClientWasm.createQueryRequest(JSON.stringify(
snapshot_block: ['head', 0],
Failed with this error:
Error: assert failed with message: expected string
at eosio_assert_message (HistoryTools.js:29)
If we output
Chain Request Schema by uncommenting line 35, we will see the required properties for
snapshot_block property from the example above seems to have been replaced with
max_block. Replacing this property fixes the issue and we receive a response to our query.
We’ve successfully made a WASM-QL connection and that concludes this guide.