How we built the largest payment channel network on Ethereum
Posted by AdEx Network on November 22nd, 2019Insights
With over 9 million transactions AdEx Network is currently the largest payment channel network on Ethereum. Here’s how we did it
A short intro to state channels and payment channels — what are they and why are they needed
Scaling is one of the biggest obstacles that blockchains face when it comes to achieving mainstream adoption. Most blockchain applications are still slow, operation costs are high, and transfer of information is limited.
This is why the concept of state channels was embraced with high hopes by the community when it was first introduced. Anyway, during the first three years since the idea was introduced, there were no production-ready implementations, just occasional rumours and beautiful dreams. It took a while before we witnessed usable state channels implementations like the Lightning Network for example.
To put it simply, state channels refer to the process in which users interact (send funds or change the state of smart contracts) with one another directly outside of the blockchain, or ‘off-chain’. Multiple interactions between two users don’t need to be stored on the blockchain, important is only the initial and the end state between them. This saves time and resources from the need to write multiple repetitive transactions or states on the blockchain.
Payment channels are one application of the state channels technology where scaling is used for unlimited, bidirectional transfers between two participants. These transfers can be performed instantaneously and without any involvement of the actual blockchain itself, except for an initial one-time on-chain creation and an eventual closing of the channel. As the name implies, payment channels are most suitable for exchange of cryptocurrency.
What payment channel networks are out there?
The biggest payment channel network is Bitcoin’s Lightning network, having $9M locked on chain. When it comes to Ethereum solutions, there are several projects focusing on payment channels but the biggest ones that are live (operational and having some funds locked on chain) are AdEx Network, Raiden Network and Connext.
Raiden Network is an off-chain scaling solution, enabling near-instant, low-fee and scalable payments on the Ethereum blockchain, working with any ERC20 token. The Raiden Mainnet launched in late 2018 and its aim is to become “the Lightning Network for Ethereum”. At the moment, Raiden network has 278 open channels and 78 unique accounts. On 12 August it had 4.57 WETH total network deposits, or around 860 USD.
Connext provides non-custodial layer 2 payment channel technology that enables instant off-chainpayments with low transaction costs. Connext launched its own its Dai Card in March 2019. The Dai Card hosts an Ethereum wallet in the user’s web browser. Users can load the card with Dai (or ETH, which will automatically be swapped for Dai). Once funded, the Dai Card can be used to send instant payments to any other Dai Card holder. On 12 August Connext had a total of $12K DAI locked and it is gradually growing.
How did we end up building currently the largest payment channel network on Ethereum?
AdEx Network has always been a solution for digital advertising, so we didn’t start the project with payment channels in mind, but we quickly realised we needed such a solution. There is a large number of interactions between advertisers’ side and publishers’ side on the platform — impressions are reported and per-impression payments are carried out, and this is why scalability is crucial.
For AdEx, using payment channels has a few important benefits:
- Firstly, it allows us to minimize the number of on-chain transactions, and that’s a huge UX improvement. In AdEx, the only on-chain transactions that you need are opening a campaign (as an advertiser) and withdrawing your earnings (as a publisher). Users do not need to learn what payment channels are or how they work, they only need to deposit/withdraw funds to AdEx.
- Secondly, because making payments does not incur any extra fees, we can use micropayments for each individual impression (or any other type of payable event).
This means publishers have a guarantee they can withdraw their revenue at any given time, unlike traditional systems where you can only withdraw your earnings for set, usually long periods, and/or only if you reach a certain threshold.
But most importantly, since the payments are per impression, this eliminates any possibility that an advertiser would cheat a publisher out of their earnings. This also makes reporting completely transparent, because you know about every impression and how much was paid for it, in real time.
We decided to call our own payment channels technology OUTPACE — Off-chain Unidirectional Trustless PAyment ChannEls. The two most important features of OUTPACE are that it’s strictly unidirectional, which simplifies the architecture, because it does not require exit games/watchtowers, and It allows multiple parties to be paid from a single channel (one-to-many).
The latter is very useful for AdEx, since advertisers on the network usually will pay many publishers, using one-to-many payment channel.
For more technical details on how OUTPACE works, you may want to read the article we wrote when we first introduced the technology 8 months ago. OUTPACE is open-source by the way, you can find it on GitHub. Now let’s talk some numbers.
More than 9 million impressions in less than two months
At the end of June, we decided we were ready to release the latest version of our platform after testing it in closed beta. First, we started rolling out our ads via AdEx Network on our other product — the media center Stremio, serving more than 100,000 daily ad impressions. We quickly added a few other publishers — two of them being among the most visited websites in our home country. We quickly added supply of 8 of the most popular display ad positions and at the moment we have a total of 11 publishers on the platform.
In less than two months, website visitors generated more than 9 million impressions on AdEx Network. This means more than 9 million payment transactions, all settled on Ethereum. We just surpassed Connext by the amount of funds locked on chain with 12,000 DAI currently locked up on-chain, so it is safe to say that at the moment AdEx Network is the largest payment channel network on Ethereum by locked up funds, and by number of transactions.
You can check our stats in real time on our Explorer. Our payment channels are so efficient, that hundreds of thousands of impression payments get settled in one Ethereum transaction, costing a mere 0.10$ in gas fees.
The technical details of our payment channels
In AdEx, each advertising campaign is an OUTPACE channel. The channel works by exchanging messages between it’s two validators. The two validators are equivalent to channel participants in Lightning/Raiden (see Alice and Bob in this example). Those messages can be used while the channel is active, by any earner in the channel, to withdraw their funds on-chain.
Currently, the AdEx Network has two validators, which we’ve named Tom and Jerry. Anyone can run a new validator, or just explore the codebase. Check out the GitHub repository.
The AdEx Platform interacts with Ethereum for depositing funds, opening campaigns, withdrawing earnings from campaigns (called “channel sweeping”) and withdrawing funds. To facilitate paying transaction fees in DAI, as well as scheduling transactions and multi-device authentication, we use a “smart” wallet, described in our Identity contract.
Let’s walk through the full process, with examples:
2. The Platform will automatically submit metadata about the channel to the validators, which will ensure it does indeed exist on-chain, and will start receiving events (impressions, clicks) for it
3. The Market will detect that the validators have started processing the channel, and it’s state will change from Ready to Active in the Market and the Explorer
4. The AdView will start showing ads from the campaign this channel is tied to
5. The AdView will send impression/click events to the validators, who will update the balances of earners (publishers) by exchanging NewState(balances, signature) and ApproveState(signature) messages between themselves
6. Now a publisher who’s earned from this channel may withdraw, by calling channelWithdraw and submitting the last signatures from the validators, along with a merkle proof of their balance in the balance tree; they may withdraw from multiple channels in one transaction (“sweeping”), thanks to our Identity contract, as you can see here. This particular transaction withdrew value incurred from ~159k micropayments, from 4 channels, and cost only $0.16 in gas fees. Keep in mind, the gas costs do not increase with larger amounts/more transactions.
In the Platform, step 6 is automated: the users see the total funds they have, no matter if on-chain or on channels. If you try to spend all your funds at once, the Platform will automatically “sweep” all channels first, making all your funds spendable on-chain.
For more details on the inner workings of the protocol, you can read our protocol docs.
9 million is a good number to start with in the context of blockchain transactions — but for ad impressions, it is modest. We are just starting to test AdEx Network and by the end of the year we are aimed at onboarding few hundred advertisers and publishers, so we believe numbers will rise significantly and they might become even more impressive pretty soon.
Are you interested in AdEx? Get in touch: