In the evolving digital landscape, businesses and developers are constantly seeking the most effective tools for tracking and analyzing data. At Origin, we’ve been using Google Analytics as the go-to solution for monitoring web-based interactions, but blockchain technology introduces a compelling alternative: tracking transactions on-chain. This approach offers unique benefits, particularly around accuracy and transparency.
The basic premise behind tracking referrals on-chain is to append some extra bytes to the calldata of any transaction originating from a decentralized app (dapp) that you control. The extra bytes do not typically interfere with the contract call (though there are exceptions), but it does increase the gas cost of the transaction by a minuscule amount.
These extra bytes are stored on-chain and are visible on Etherscan or on any other indexer. In Origin’s case, we use Subsquid to tag transactions that have calldata ending with a known byte array, so that we know which transactions originated from our dapp.
This technique has been used by NFT marketplaces for some time and is how transaction volume can be attributed to aggregators like Blur or Gem. NFT infrastructure projects like Reservoir have built the functionality directly into their SDK, though the technique isn’t yet common within DeFi.
Implementing an on-chain referrer system is a relatively simple process, but there are a few key considerations. You’ll need to decide what kind of attribution to use (first touch vs. last touch), and how you’ll store the data. Here’s how I set up an on-chain referral system for Origin Protocol.
Here’s how it works from start to finish:
Advantages of On-Chain Tracking
Potential Limitations
On-chain referral tracking offers some compelling advantages over traditional tracking mechanisms, such as its immutability, transparency, and resistance to common web tracking issues. While it does come with its own set of challenges, including increased gas costs and potential incompatibilities, the benefits likely outweigh these limitations and the technique is worth considering as an alternative.