How to use sscjs library to find info in hive-engine:

It's something really simple that I've struggled a lot, because it's explained for devs that already know how hive-engine works around. So here it is the three steps tutorial to use sscjs:

First step: setting up a basic html file

Basically we create a file and name it whatEver.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
</body>
</html>

Then we add these these lines to the file:

<script src="https://unpkg.com/axios/dist/axios.min.js" ></script>
<script src="https://cdn.jsdelivr.net/npm/sscjs@latest/dist/ssc.min.js" ></script>

There we go:

<!DOCTYPE html>
<html lang="en">

<head>
    <script src="https://unpkg.com/axios/dist/axios.min.js%22%3E
    
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
</body>
</html>

Second Step: Setting console for testing

So we open the file in a browser and open the console and type this:

const ssc = new SSC('https://api.hive-engine.com/rpc');

image.png

Step 3: Testing the Library:

We can search one of the three contracts (tokens, market, NFTs)

ssc.getContractInfo('tokens', (err, result) => {
    console.log(err, result);
})

So we type that in the console and press enter:

image.png

So we got some info about the contract, owner:hive-engine, and we got the contract tables, now we can take any of these tables and search info related to that table:
Let's take the delegations table as example:

ssc.find('tokens', 'delegations', { }, 100, 0, [], (err, result) => {
    console.log(err, result);
})

So basically this function looks into the "delegations" table in the "token" contract. And it throws "100" delegations starting from "0". We could have said "500, 3999" and it would throw in the firsts 500 delegations after the 3999 one

image.png

Now we can search for specific stuff inside the Curly braces{}. We can use any of the properties there created/from/symbol/quantity/etc. lets take the symbol as an example {"symbol":"LEO", "to:"leo.voter"}

Then we get all the Leo delegations to the account leo.voter:

image.png

That's it! and remember:

image.png

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center