All my open source tools/libraries written in Rust to work in blockchain/DeFi space (as of end of 2022)

All my open source tools/libraries written in Rust to work in blockchain/DeFi space (as of end of 2022)

I would like to share my Rust tools/libraries in which I did complete (a few still not feature-complete but functional) all of them within the 1st quarter of this year 2022 (while crypto was still in the upside before collapse...) just to solve my own problems in interacting with smart contracts out there on EVM-based chains.

If you are a command-line nerd user who writes code with vi/vim or some other tools in terminal then these tools are designed to accommodate on such aspect.

All of the projects can be installed via cargo install ... command as they are all available on crates.io.

So here we go,...

1. evmscan

This project is a library as a foundation to create other standalone tool projects as it utilizes API of bscscan.com (for BNB Smart Chain), etherscan.io (for Ethereum), and polygonscan.com (for Polygon chain) in which user can choose which chain to interact with. Although it is not feature-complete yet, but it's functional to the point that it fully offers what I ever need. If you feel like you want to expand, feel free to contribute to it.

The set of shared APIs among all those websites (service providers) are very similar as the team behind is the same for all those. So it's manageable in terms of implementation.

What I like about Rust is "unwrap" in which it makes the code clean as you need to handle each case e.g. success or failure case in which each failure case consists of multiple sub-case.

2. tracpls

tracpls helps grab the smart contract code + ABI specification from the target contract address. It totally feels too cumbersome to go to explorer websites then click on "Contract" tab then further inspect smart contract code file by file with a limited window space. It's too time consuming with bad ergonomic. As you work solely on terminal, then why not streamline the process and let it grabs all source files + ABI for you, so you can view it with your favorite text editor? That's the goal of this tool.

See extracted detailed information about this tool from its github repository as follows

tracpls's text output from --help
Command line options for tracpls
example of using tracpls
Example usage of tracpls

As seen above, there are multiple options to filter through what you might need, says all source files with ABI, or only ABI, with ability to write into destination folder or directly view it via piping output straight into vi/vim directly. Try it.

3. appvkek

DeFi investors definitely interact with lots of smart contracts out there. The most important thing is security. They approved the amount of token to be spent on behalf by the smart contract itself. So if individual allowed it years ago, and something bad happens to the project one has invested in e.g. smart contract has flaw allowing hacker to steal your tokens. So to close such hole, firstly we have to identify which smart contract we ever have interacted with that need to be fixed. appvkek helps on this regard.

It will list all of the contracts user has ever called its "approve" function. That action alone means you opens the door for possibility of future disaster if something ever happens to such project.

Let's role play via the following scenario

  • Investor A hears the worrisome news ahead of time about the project he/she has invested in.
  • Investor A invested in so many projects that he/she cannot remember whether this project is as part of his/her portfolio
  • Investor A uses appvkek tool to list all contracts he/she ever approved
  • Investor A can pin-point which contract by either grep the result via name of the token, or use contract address from the project page then inspect amount of allowance ever been set.
  • Investor A can use project's front-end website, or next tool "crunner" to fix the problem thus prevent anything bad possibly happens by setting a new allowance amount to be 0.

Implementation tries to execute multiple queries all at once as many as possible (but still respect the rate limit baked into the code), finally it waits for all the result in each iteration via futures.

It can finish the work processing for all 302 contracts associated with a particular wallet address within 4.92 seconds.

benchmarked execution time of appvkek via --execution-time
Benchmark the time; can be enabled via --execution-time option flag.

Note also that each contract address user has approved can consist of multiple spender addresses. appvkek will list all of spender addresses associated with such contract address as well.

4. crunner

We can say that this is a command line version to execute contract's function. Instead of using front-end website, or explorer to execute function, this tool can do the same. In additional, it provides ability to automate the work as users can embed executing the command into script.

It has the following features

  • Dry-run executing the contract's function to get estimated gas fee
  • Execute getter or setter function call
  • Execute RPC-ETH call (for now just balance end-point)

It's best to see from example (as written on README.md as seen on github page).

dry-run to estimate gas fee example for crunner
Dry-run executing contract's function just to estimate gas fee
example of executing getter function of crunner
Execute getter function call
example of executing setter function of crunner
Execute setter function call
example of executing RPC-ETH call of crunner
Execute RPC-ETH call

5. inoutflow

A simple tool to print out the flow of native token (BNB, ETH, or MATIC) of such chain user executes the tool on. It works on both EOA (wallet address), or contract address.

The idea to make this tool came up to me whenever I wanted to know the current balance and simple flow (in/out) of native token of target address as a summary without taking a peek into chain explorers. So I DIY.

example usage of inoutflow
Example usage of inoutflow.

There is an interesting technical tips on how balance get calculated as it involves normal, and internal transaction. I extracted my finding here.

interesting technical tips from developing inoutflow
Interesting finding on how to calculate balance of address

6. contractdiff

For the particular circumstance that you have doubt among the two contracts whose code probably are the same, then contractdiff can help quickly answer that. This is especially useful when contract code is not uploaded by the author, thus byte by byte comparison is a way to inspect unless you want to decompile and inspect its behavior yourself.

example output from contractdiff
contractdiff visually outputs differences in color similar to how git diff does the job

Underlying it bases on Myers algorithm (as git diff uses) to diff bytecode between the two contracts. Differences are based against the first contract supplied as first main parameter of its command argument.

As seen from above image, the tail end bytes are the only difference which can tell us that the two contract code are the same, but with different state variables supplied at contructor method to initialize each contract. If you see result like this, then you can highly be sure both contract code are the same.

7. keccak256-cli

This tool helps output the signature of the method as method id as it is shown on blockchain explorer. It bases on keccak256 encryption, accepts input from stdin or text file with multiple options depending on use cases.

example usage of keccak256-cli
Example of usage for keccak256-cli.

It is pretty useful when you do a detective work deciphering compiled contract code, or inspecting transactions over blockchain explorer. Yes, you can use online website to help generate method id for you, but I do love working solely on terminal, no one can stop me from implementing this stuff ;)

8. rustelebot

Telegram is the most user friendly and API ergonomic to work with compared to all other messaging applications. So most of the case, whenever I want to notify something to myself, I use Telegram.

rustelebot is created to accommodate sending a message from Rust application to Telegram with ease. It mainly focuses on sending message API, and is not implemented exhaustively in terms of features. But at least, it offers sending message either in synchronous, or asynchronous, either in raw text, Markdown V2, or HTML format. That covers most of the use cases.

example in using rustelebot - part 1
Example of using rustelebot API.
example in using rustelebot - part 2
Sending in asynchronous way is also possible.

9. bybit-shiprekt (extra)

Although this tool doesn't totally relate to blockchain or DeFi space but mostly about CEX, but I tempted to include it as well. Take it as an extra :)

For reasonable period of time, I has also traded futures on Bybit exchange. This tool is inspired by Kraken Shiprekt Telegram group in which it notifies subscribers for liquidation event from traders out there for inverse futures assets on Kraken exchange. So I implement it for Bybit with similar functionality. Although my live Telegram group is defuncted now but you can use it to set up your own Telegram group just to notify you with such events.

Liquidation events could be useful for traders as you can roughly tell which direction the price is heading at the moment when such event received on your end. Either act fast to grab the opportunity of price spike, or take further action to protect your current position.

This tool utilizes rustelebot as well.

example notification message sending from bybit-shiprekt to notify liquidation events
bybit-shiprekt notifies liquidation events from traders across assets in futures market.



If you ever use any of my tools above, or take it to another step to implement any higher level tool on top of it, please feel free to let me know. I always want to know the benefits users get from it in various ways.

That's all for now. Until next post.

Great post & very usefull toolset :-) Would you also explore Cosmos SDK ecosystem and developments in Go ?

To view or add a comment, sign in

More articles by Wasin Thonkaew

Others also viewed

Explore content categories