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
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
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.
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
It's best to see from example (as written on README.md as seen on github page).
Recommended by LinkedIn
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.
There is an interesting technical tips on how balance get calculated as it involves normal, and internal transaction. I extracted my finding here.
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.
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.
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.
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.
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.
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 ?