Blockchain Betting for Football with External Adapters and Chainlink Keepers

Harsha R
4 min readJul 20, 2021

In earlier posts (Part 1 and Part 2), we introduced the concept of blockchain-based betting and its advantages. In this post, I will discuss betting on football matches using Chainlink’s External Adapters.

How is this different from betting on Chainlink’s pricefeeds that we introduced in Part 1? The data for the pricefeeds was readily available to us on-chain through Chainlink APIs. We only had to call a simple API and the latest price of any token was reliably available to us.

But for football matches there is no readymade on-chain information. Since smart contracts are inherently disconnected from the outside world, the information is available off-chain and needs to be brought on-chain. The deterministic nature of blockchain requires an oracle. You can read more about Chainlink Oracles here and here.

We also demonstrate the use of Chainlink Keepers and how they help us resolve bets.

External Adapters and Chainlink Oracles

Remember that Chainlink only provides the infrastructure to bring off-chain data on-chain. We need a reliable way to bring football match results on-demand. For this purpose, we need three things:

  1. Source of reliable match data.
  2. External Adapter(EA) to fetch match data on-demand.
  3. Chainlink Oracle Node to call the EA and bring the match data on-chain.
Bet on football matches with External Adapters and Chainlink Keepers

Source of Match data: RAPID API and API-Football

Rapid API is a marketplace for various APIs. We picked API-Football because of their in-depth match data and reliable results. These APIs provide the raw match data which we will customise and extract the relevant data.

Please note that these APIs operate on a freemium model and you may have to pay for the usage.

External Adapters

External Adapters (EA) are the connection between a Chainlink Oracle Node and the real-world data. EAs take raw real-world data and convert it to the format required by the smart contracts. Checkout the related EA documentation and tutorials.

I created an EA for the football results and deployed it on a Digital Ocean server. You can see the code on GitHub.

Chainlink Oracle Node

When the smart contract requires data from an Oracle, it needs to build a request by supplying the relevant “oracle id” and “job id”. Each Oracle is identified by an “oracle id” and can run several jobs. Checkout all the Oracles and their capabilities here.

A job running on an Oracle will make a request to the EA and fetch the relevant data. This data is generally the match result (but it can be any other player / team / match related information) required by the smart contract to adjudicate the bet.

Since running our own Oracle Node is a lot of work, I went scouting on the Chainlink Discord channels to find someone to host our job. The good people at LinkRiver were happy to help and easy to work with.

Once you have the “oracle id” and the “job id”, you can now incorporate it into your smart contract.

Keepers — How we resolve bets

Smart contracts are inherently disconnected from the outside world and don’t know “when” to fetch a match’s result (or whether a particular match is completed). The user would need to request data from the EA, by expending gas fees. If the user is unaware of when the match will be completed, they might end up attempting to fetch the results multiple times.

Chainlink Keepers offers a way out of this. You register for a service and configure it to check the match results periodically. This way the user doesn’t need to periodically check for the result and it saves their gas fees. Bets are resolved as soon as the EA has the match result.

Future Work and Improvements

  1. Currently we use only a single source for raw match data. Isn’t this a bit of centralisation in the decentralised world? True, but given time and effort we could add multiple sources of data and the EA could respond to the Oracle only when multiple sources confirm a result. This is not a technical problem, just a matter time and effort.
  2. A bot to create and join football bets much like the one we discussed in Part 2? This is eminently possible, and again it is a matter of time and effort.

Special thanks to Roger and the LinkRiver team for hosting our EA.

This work was done by Sree Harsha R and Mithun KM.

--

--