Skip to main content

Using Bstream Webhooks

Bstream webhooks allow you set up integrations that subscribe to a certain blockchain event within your code. When that event occurs, Bstream makes an HTTP request to the URI provided by you.

What is a webhook?

In simple terms webhooks are automated messages sent from a server when a specific event happens. You can catch a webhook message via a simple API endpoint. After catching the message, you can execute specific functions as per your needs.

webhook

Listening to Bstream webhooks

Creating a webhook

Webhook URI is a simple API endpoint that you can set up to receive webhook messages. You can use replit.com to set up a flask server for testing webhook messages. Here is a simple flask server that you can use to test webhook messages.

from flask import Flask, request
import json
app = Flask(__name__)

@app.route('/')
def helloWorld():
return "Simple Flask Server to test Bstream Webhooks"

@app.route('/bstream-webhook', methods=['POST'])
def receive_payload():
if request.method == 'POST':
data = request.get_data()
print("Received Payload:", data)

'''Now you can execute your function whenever any on-chain event happens. Be it someone
buying/selling/transferring something etc.'''

return f"Received webhook data: {data}", 200

return 'Invalid Request', 400

if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)

Adding webhook URI to Bstream

  1. Go to Bstream and click add Stream

    alt_text

  2. Now select the type of event your want to stream within your code. For instance we will choose 'Transfers' to stream all USDT transactions above $1M

    alt_text

  3. Fill the form according to your need. Here we have added token address of USDT which is 0xdac17f958d2ee523a2206206994597c13d831ec7 and set the minimum amount to $1M

    alt_text

  4. Now click add webhook button from integration section

    alt_text

  5. Enter the webhook URI, webhook label and any optional headers (if required) and click Finish alt_text

    Note

    Make sure your webhook URI private to you. Anyone with access to your webhook URI can send you webhook messages.

  6. After saving it, you will start receive webhook messages of all USDT transactions above $1M. The response message is a json object containing all the details of the transaction.

    KeysDescription
    streamNameThe name of the stream
    subjectTwitterUserNameTwitter username of the subject
    subjectTwitterNameTwitter name of the subject
    subjectAddressEthereum address of the subject
    blockNumberNumber of the block
    blockHashHash of the block
    hashTransaction hash
    fromSender's address
    toReceiver's address
    gasGas used in the transaction
    gasPricePrice of gas
    maxFeePerGasMaximum fee per gas
    maxPriorityFeePerGasMaximum priority fee per gas
    nonceTransaction nonce
    chainIdChain ID
    transactionIndexIndex of the transaction in the block
    typeType of transaction
    valueValue sent in the transaction
    vV parameter of the transaction
    rR parameter of the transaction
    sS parameter of the transaction
    inputInput data of the transaction
    accessListList of access information
    functionNameName of the function called in the transaction
    buyerAddress of the buyer
    numberOfSharesToBuyNumber of shares to buy
    receiptStatusStatus of the transaction receipt
    addressAddress in the log
    topic0Topic 0 in the log
    topic1Topic 1 in the log
    topic2Topic 2 in the log
    topic3Topic 3 in the log
    dataData in the log
    eventNameName of the event logged
    traderAddress of the trader
    subjectAddress of the subject
    isBuyIndicates if it's a buy transaction
    shareAmountAmount of shares involved in the transaction
    ethAmountAmount of Ethereum involved in the transaction
    protocolEthAmountAmount of Ethereum for the protocol
    subjectEthAmountAmount of Ethereum for the subject
    supplySupply information