Solana Blockchain data scraping

Matthew Leung
Coinmonks

--

As the transactions on Blockchain can be accessed as public data, we can develop a scraping client to retrieve the data in each block for analysis.

Here is the code in Rust API I used to access the Solana Blockchain.

Create the RPC Client.

RpcClient::new("https://solana-api.projectserum.com".to_string());

Get the current Epoch

client.get_epoch_info().unwrap();

Get the time slot number (absolute_slot) for the Epoch intervals.

start_slot = epoch_start.absolute_slot;
end_slot = epoch_end.absolute_slot;

Get the transaction blocks between 2 time slot numbers.

let blocks = _client.get_blocks(start, Some(end)).unwrap();
for s in blocks {
let _blk = _client.get_block(s);
// get the data we need from each block

Each Block contains a list of transactions. Each transaction has meta data, messages, the balances before and after the transactions, and the account lists.

There are many different kinds of messages. From my testing, I found the following 2 messages will indicate transfer.

"Program 11111111111111111111111111111111 success""Program log: Instruction: Transfer"

I filtered out the messages, and then subtract the post-balance from the pre-balance. That can trace how much lamports transferred between the account keys.

I extracted these information for each transaction and feed into the Neo4J graph DB to build the relations for all the transfer between different Accounts. Here is the Cypher Query to build the transfer relationship in Neo4J.

MATCH (ac1:Account {key: $ckey}),(ac2:Account {key: $dkey}) 
MERGE (ac1)-[rel:TRANSFER_TO]->(ac2)")

The following shows the visualization of the transfer graph. Each red node represents an Solana Account, and the directed link is the transfer_to relationship.

The graphs showed a few busy clusters where the accounts within transfer lamports with each other.

The graph DB can enable many analysis such as query which accounts are the top recipient. We can easily trace the accounts clusters that has frequent transfer to certain suspect account. That can help to identify money laundering.

The full code of the scraper can be downloaded from my Git repo.

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--