Solcast SDK
Solcast is notification service built for Solana.
One of the main functions of Solcast is to observe Solana blockchain.
Each new block and transactions in it are parsed in search of transactions linked with Public Keys Solcast is tracking.
When transaction with tracked Public Key is found events are generated for that Public Key and sent to Consumers that are interested in events from said Public Key.
Type of events are:
- SOL balance changes
- SPL balance changes
- NFT balance changes
Installation
npm i @solflare-wallet/solcast-sdk
Usage of Webhook SDK
Simple usage:
const {Solcast} = require('@solflare-wallet/solcast-sdk')
const {PublicKey} = require('@solana/web3.js')
async function main() {
const solcast = new Solcast(process.env.SOLCAST_API_KEY)
console.log(await solcast.webhooks.all())
try {
const webhook = await solcast.webhooks.create("http://localhost/webhook/events", [
new PublicKey("ABcD...0NPL"),
]);
console.log(await solcast.webhooks.get(webhook.id))
console.log(await solcast.webhooks.update(webhook.id, [
new PublicKey("LniM...C2BB"),
], []))
console.log(await solcast.webhooks.all())
console.log(await solcast.webhooks.remove(webhook.id))
console.log(await solcast.webhooks.all())
} catch (error) {
console.log(error.message)
}
}
main()
Webhooks
Solcast Consumer accounts with Webhook API enabled can create and manage webhooks.
Each webhook has set of Public Keys that will be tracked and events about them sent to webhook's URL.
Solcast sends events in buckets of data in intervals of 5-10 seconds, if no events are available in a bucket, it will not be sent to the Webhook.
Each bucket is sent over POST HTTP request, and includes hash
field which is there to prevent both replay attacks and unverified payloads. We encourage Consumers to check always validity of hash
field.
|| Event bucket Hash
const secret = 'cdda0...589e0e6'
const hashString = secret + '.' + JSON.stringify(bucket.data)
const hash = crypto
.createHash('sha256')
.update(hashString)
.digest('hex')
|| Example of event bucket sent to webhook
{
"id": "ec2916a8ede53a061a46dab32a4bf58958eb54cb",
"version": "1.0.0",
"data": [
{
"signature": "inboundSolSignature",
"tokenAddress": null,
"nft": null,
"token": null,
"decimals": 9,
"publicKey": "AC7YHa5qAm1EwLPG6Qn2reRPCzYEyUPZchQkAyRMYysf",
"balance": "1",
"change": "330000000",
"type": "sol"
},
{
"signature": "outboundSLRSSignature",
"tokenAddress": "SLRSSpSLUTP7okbCUBYStWCo1vUgyt775faPqz8HUMr",
"decimals": 6,
"nft": null,
"token": {
"mint": "SLRSSpSLUTP7okbCUBYStWCo1vUgyt775faPqz8HUMr",
"symbol": "SLRS",
"name": "Solrise Finance",
"logoURI": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/SLRSSpSLUTP7okbCUBYStWCo1vUgyt775faPqz8HUMr/logo.png"
},
"publicKey": "AC7YHa5qAm1EwLPG6Qn2reRPCzYEyUPZchQkAyRMYysf",
"balance": "2000000",
"change": "-999000",
"type": "spl"
}
],
"hash": "4f75feb60edbad9f93b33e847b6974b8687b480c6192816c96c6722cfd91ae1f"
}
Example webhook secret: cdda02f9a8dee5826db3578fb00d7e56c72b4e4e6347d26989657a9e0b68a66c4890dd4bfd865f44b710edd118f2a3fe3915bd49c97e52acc4f02d017589e0e6