defi-terminal is a browser-based CLI for DeFi operations. You can swap tokens, check prices & more
defi-terminal is a browser-based CLI for DeFi operations. You can easily swap tokens, check prices/charts, & run RPC calls directly, and trace transactions by hash & more. I was inspired to build this as a middleground between interacting with dApp frontends directly and direct smart contract invocation. Some of the commands are:
swap [classic/limit/fusion] <amount> <token0> <token1> - Swaps tokens based on the best quote via 1inch
price [token] --network <ethereum,optimism,arbitrum,base,etc> finds the price of a token whitelisted on 1inch (over 1000+ currencies supported)
chart <token> <token2> --type <candle/chart> --network - loads a price chart via 1inch API (also supports 1000+ tokens)
rpc <method> <param1> <param2> <param...> - allows you to call RPC methods call on different networks via 1inch
gas <amount> - get a quote for how much gas is gonna cost via 1inch API
networkinfo --network <ethereum,optimism,arbitrum,base,etc> - fetch information for a given network
nft_balance <address> - get a list of NFTs that.a given address has across all chains via 1inch API!
& more!
Some of the inspirations for this project were softwares such as OpenBB, Godel Terminal, and Bloomberg Terminal. I find going on frontends for making swaps on DEXes, protocols, & services tedious, but also invoking smart contracts directly for DEXes is impractical. This was a concept for a common middleground for DeFi enthusiasts. Furthermore, functionality and features are fragmented across many platforms. 1inch was a great platform to utilize for this idea as they are an aggregator of many DEXes.and offer an extensive API.
We utilize the 1inch API for the most part. We first built a terminal by developing the common patterns, my friend/teammate built a proof of concept on Monday, but was unfortunately unable to collaborate fully due to his schedule. We instead made the tough decision for me to build solo, and I created the terminal using his non-browser CLI as inspiration.
I used a Next.js 15 project with serverless functions to call the various 1inch API endpoints. I spent the first couple days solely researching how the swaps functioned and how to integrate them properly in a project.
src/components/commands.ts handles the functionality for hooks and operations for triggering defi operations, and the endpoints (Which is a 1000 line file, I apologize). Arguably the most difficult functionality that was successful was the limit-order-sdk & cross-chain-sdk. Classic swaps were easy, limit orders took me a while to implement, because we had to restructure the order class instance beteween endpoints, but luckily we found a method order.build and fromDataAndExtension(order, order.extension). Unfortunately, I did not get a working implementation with cross-chain-sdk or regular Fusion+ swaps because the API was unreliable for me, but I hope to offer atomic swaps or bridge swaps in a later release.
We used a combination of the API endpoints for different commands, for instance the trace command uses an RPC call eth_getTransactionByHash from 1inch to fetch the block number when calling the 1inch API for trace transaction by hash & block number. That is also available as a command.
Also, for token prices and charts, we use the '1inch whitelisted multi-chain tokens' API endpoint to retrieve token data & support as many tokens as possible. I also used this endpoint for swaps, and charts. We also use the chart API datapoints, but it retrieves only up to 60 datapoints from their API, which is a bit lackluster. In another release, defi-terminal probably would be better using another service for retrieving data points. We use the lightweight-charts package to visualize these charts.
Some of the other tooling we use is rainbow-kit, wagmi, & viem.