I have a file called defichain.js and am trying to communicate with the defichain blockchain via OCEAN REST API in my project. I am using Node.js version 16.14.2. I am running the .js script with the latest version of truffle.
I already managed to print out the WhaleApiClient object in the console to check its available functions, so at least it is recognizing the client.
Anyways, when I am trying to get the current stats of the DeFi-Chain Blockchain (e.g. number of masternodes), I get TypeError: fn is not a function.
Clearly I am not calling any function named fn here.
const { WhaleApiClient } = require('@defichain/whale-api-client')
const client = new WhaleApiClient({
url: 'https://ocean.defichain.com',
timeout: 60000,
version: 'v0',
network: 'mainnet'
});
console.log(client); // prints client object with all of its categories
console.log(client.stats.get()) // prints Promise { <pending> }
// it seems like something is wrong here :(
client.stats.get().then((data) => {
console.log(data)
})
I am expecting an output in the console something similar to:
{
"data":{
"count":{
"blocks":1831387,
"prices":97,
"tokens":146,
"masternodes":11044
},
"burned":{
"address":156009915.966001,
"fee":237127,
"auction":473292.86501403,
"payback":49335487.46135226,
"emission":82354933.12182175,
"total":288423830.22026604
},
"tvl":{
"dex":874830839.7451664,
"masternodes":956478286.6812595,
"loan":260332219.5450214,
"total":2091641345.9714475
},
"price":{
"usd":4.164032593301086,
"usdt":4.164032593301086
},
"masternodes":{
"locked":[
{
"weeks":0,
"count":7435,
"tvl":655918414.0967871
},
{
"weeks":520,
"count":2859,
"tvl":238099383.6849561
},
{
"weeks":260,
"count":750,
"tvl":62460488.89951629
}
]
},
"loan":{
"count":{
"collateralTokens":6,
"loanTokens":28,
"openAuctions":8,
"openVaults":9915,
"schemes":6
},
"value":{
"collateral":260332219.5450214,
"loan":136835351.84522375
}
},
"emission":{
"masternode":84.5329931,
"dex":64.54739497,
"community":12.45295518,
"anchor":0.05072487,
"burned":92.04027360305092,
"total":253.62434172305092
},
"net":{
"version":2070000,
"subversion":"/DeFiChain:2.7.0/",
"protocolversion":70028
},
"blockchain":{
"difficulty":22297887949.45695
}
}
}
For more information on Ocean REST API, Defichain and its Jellyfish library:
Ocean REST API is a quite unknown project and still in its early stages. Ocean REST API is a global infrastructure project hosted by DeFiChain to simplify building decentralized light applications. Powered by the Jellyfish Ecosystem, Ocean Nodes are globally distributed around the world, any API request is served by the node nearest to the requester with auto fail-over.