Coinmonks
Published in

Coinmonks

Commanding the Line

Many of us live and work on the Linux command line.

Using Linux Pipes

First, I’ll start by showing you a command our user shared with us:

chifra export --cache --articulate \
--first_block 12550000 --last_block 13520000 \
--fmt csv 0x6b175474e89094c44da98b954eedeac495271d0f | \
grep 'approve' | \
tr -d '"' | \
cut -d ',' -f1,2,5,6,13-20 \
> dai_uniswapv2_approvals.csv

Can We Improve on This?

Yes.

How?

There’s are five things going on in the above command:

  1. Filtering the records for approvals with grep
  2. Extracting only five of the many fields in each record with cut
  3. Removing quotes with tr
  4. Storing results in a file with a redirect (>)
chifra export --fmt csv \
--articulate 0x6b175474e89094c44da98b954eedeac495271d0f

Filtering Records for Approvals

If one runs the commandchifra export --help, one sees this summary:

chifra export [flags] \
<address> [address...] [topics...] [fourbytes...]
chifra abis 0x6b175474e89094c44da98b954eedeac495271d0f | grep approve
fourbyte       type         name        signature
-----------------------------------------------------------------
0x095ea7b3 function approve approve(address,uint256)
chifra export --fmt csv --articulate \
0x6b175474e89094c44da98b954eedeac495271d0f \
0x095ea7b3

Field Selection

Note: The following section describes an experimental feature of TrueBlocks. I may be removed or altered in future releases. Use with caution.

DISPLAY_FORMAT="[{BLOCKNUMBER}]" \
chifra export --fmt txt --articulate \
0x6b175474e89094c44da98b954eedeac495271d0f \
0x095ea7b3 2>/dev/null
DISPLAY_FORMAT="[{BLOCKNUMBER}][{TRANSACTIONINDEX}]" \
chifra export --fmt csv --articulate \
0x6b175474e89094c44da98b954eedeac495271d0f \
0x095ea7b3 2>/dev/null
DISPLAY_FORMAT="[{BLOCKNUMBER}]\t[{TRANSACTIONINDEX}]\t[{FROM}]\t[{TO}]\t[{COMPRESSEDTX}]" \
chifra export --articulate \
0x6b175474e89094c44da98b954eedeac495271d0f \
0x095ea7b3 2>/dev/null
blocknumber    transactionindex   from   to   compressedtx

Storing the Results in a File

So far, we’ve eliminated grep, cut, and tr. Can we eliminate the redirect?

DISPLAY_FORMAT="[{BLOCKNUMBER}]\t[{TRANSACTIONINDEX}]\t[{FROM}]\t[{TO}]\t[{COMPRESSEDTX}]" \
chifra export --articulate \
0x6b175474e89094c44da98b954eedeac495271d0f \
0x095ea7b3 --output dai_uniswapv2_approvals.csv

Performance

Here are the results of testing the two commands for speed:

chifra list --count 0x6b175474e89094c44da98b954eedeac495271d0f`

Support Our Work

TrueBlocks is totally self-funded from our own personal funds and a few grants such as The Etheruem Foundation (2018), Consensys (2019), Moloch DAO (2021), and most recently Filecoin/IPFS (2021).

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

Also, Read

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thomas Jay Rush

Blockchain Enthusiast, Founder TrueBlocks, LLC and Philadelphia Ethereum Meetup, MS Computer Science UPenn