Twitch technical solution

Twitch technical solution


Written by: David Jiménez, Technical Leader at Change The Block.

 

On the Change The Block platform, a new contract creation modality was added. It is Twitch-type contracts, which like the rest, consists of creating a Smart Contract on the Ethereum Blockchain network. 

 

The objective of these contracts is to close deals with different influencers who use the Twitch platform to upload digital content to their channel with some advertising.

Smart Contracts, as the name suggests, are smart contracts that are capable of executing and enforcing themselves, based on a series of instructions in a programming language. They are stored on the blockchain immutably, transparently, and securely. The latter means that no one will be able to manipulate data related to a contract without alarm bells ringing.

These contracts are executed on Ethereum, which is a decentralized digital platform. We can understand it as an operating system to be able to run our applications (smart contracts). It gives us the advantage of performing operations without intermediaries or commissions.

Solidity is the programming language used to create these smart contracts, and Geth is the client that we use to communicate with the Ethereum Blockchain network.

Within Ethereum there are different networks, which can be for testing our applications or for production. In this case, we will make use of Rinkeby, the test network to simulate the execution of contracts with fictitious cryptocurrencies.

After briefly explaining the purpose of the functionality and the technical terms, we will explain the process step by step until the contract is closed/finalized:

 

1.Collect user data.

From the platform, the user will have to select the contract and enter the necessary data, mainly the influencer’s channel, the hashtags that must appear in the streaming and the agreed date for the video upload. These data are mandatory, as they are used by the system to validate compliance with the contract.

The twitch API allows us to obtain a wide variety of information including the number of views, the game that has been played, etc.

For this experiment we decided to work with the influencer’s channel and the hashtag to be used, replicating the model used in social media advertising campaigns.

 

2.Smart Contract Creation

Through the API, the contract information is received, and the smart contract is created in Rinkeby. The different hashtags agreed in the contract will be stored.

At this point, we make use of the Web3js javascript library, which allows us to connect to our Ethereum network and interact with it (create contracts, perform transactions … etc).

Well, with this library we create the contract by sending it the information collected from the user, which is stored in it.

The ABI (Application Binary Interface) is the standard way to interact with contracts in the Ethereum ecosystem. That is, the contract is encoded for the network to work with the contract.

 

3.Contract verification

The system is responsible daily for reviewing those contracts dated the previous day, and that they are signed by all the intervening parties to start with the collection of the published data. This was designed to avoid a user uploading a video at the end of the day and the system not detecting it.

If the system finds a contract to verify, it will query the influencer’s channel and obtain all the videos uploaded on that date. Once collected, all the hashtags posted on each of them are collected and stored in the database.

To obtain this data, we consume the Twitch API, which returns a series of public data of users and channels. As a requirement, we are asked for a Twitch account and the generation of a token for the connection.  Subsequently, the Smart Contract contrasts the data with the variables defined within it in order to determine compliance with the contract.

 

4.Validate contract

When the system has all the information collected from the influencer’s channel, the API calls the smart contract through the web3js library, and it is in charge of checking that the hashtags initially agreed upon are in the list of hashtags published in Twitch. Finally, the contract will emit an event with the result (fulfilled / not fulfilled), and a variable is modified indicating that the contract was checked.

As mentioned above, the Twitch API is much more complete than that of other platforms commonly used by influencers (Youtube, Facebook) and allows us to access a lot of streaming information, such as streaming language, user channel, etc. so that in the future, it could be used to create much more complex contracts that take into account other variants such as the number of active users or the game being played and even differentiate the contract by region.

 

5.Closing the contract

The API will receive the event from the contract with the result, and this will be saved in the database. In the application, in the contracts section, the user will be able to see if the contract was fulfilled or not by the influencer.

The data that could be consulted in the Ethereum network related to a contract are:

  • Contract status. Whether it was closed or not.
  • The hashtags that were agreed upon for the video. 

For the future, other data related to the Twitch channel itself could also be stored, which can be of great value when signing a contract with agencies.