Monitoring Withdrawals and Deposits for 1000s of Binance Exchange Wallets
In this guide we will utilize the Protobuf Kafka streams provided by Bitquery to monitor withdrawals and deposits for a large number of Binance Exchange Wallets on BSC network. You can read more about Kafka solution by Bitquery here.
Checkout the complete codebase for any issues in the tutorial.
Prerequisites
- Create a project folder with the given command.
mkdir bsc-exchange-wallet-monitoring
- Install the dependencies using the command line.
pip install bitquery-pb2-kafka-package
- Create the file structure with the following commands.
touch main.py
mkdir helpers
cd helpers
touch convert_bytes.py
Helper Functions
In this section we will discuss the code written inside the helpers folder.
Convert Bytes
This functions takes the base58 encoded bytes as parameter and returns readable string values.
import base58
def convert_bytes(value, encoding='hex'):
if encoding == 'base58':
return base58.b58encode(value).decode()
else:
return value.hex()
Imports
import os
import uuid
from confluent_kafka import Consumer, KafkaError, KafkaException
from google.protobuf.message import DecodeError
from evm import token_block_message_pb2
import binascii
import base58
import json
from helpers.convert_bytes import convert_bytes
from helpers.print_protobuf_message import print_protobuf_message
Creating Kafka Configuration
The credentials such as username and password could be received by contacting the Bitquery team via - sales@bitquery.io
group_id_suffix = uuid.uuid4().hex
conf = {
'bootstrap.servers': 'rpk0.bitquery.io:9092,rpk1.bitquery.io:9092,rpk2.bitquery.io:9092',
'group.id': f'{username}-group-{group_id_suffix}',
'session.timeout.ms': 30000,
'security.protocol': 'SASL_PLAINTEXT',
'ssl.endpoint.identification.algorithm': 'none',
'sasl.mechanisms': 'SCRAM-SHA-512',
'sasl.username': username,
'sasl.password': password,
'auto.offset.reset': 'latest',
}