-
-
Advertisers can create a contract and offer a social media promotion deal to influencers
-
The homepage shows a list of all the currently deployed offers
-
Influencers can make a sponsored post and redeem a reward based on the number of post interactions
-
An example of a JavaScript social media deal contract
Check out the Youtube video!
The demo website requires a password to access. Judges or others associated with Chainlink Labs, please message me to request the password.
Inspiration
I want to be able to access any data on the internet and perform generalized off-chain computation on a decentralized oracle network with a single smart contract function call.
Background
While Chainlink enables smart contracts to access verifiable data from the real world, this aggregated data is restricted to the existing feeds on the Chainlink Network. The AnyAPI feature and external adapters allow for additional functionality, but they still have limitations. AnyAPI has limited computational capabilities and no support for APIs that require authentication. External adapters can access authenticated APIs and offer flexible computation, but they must be set up ahead of time and a new adapter must be created for each differing use case. Furthermore, implementing aggregation requires deploying the adapter on every node in a DON.
What it does
The Universal Adapter allows users to fetch any data from the internet using JavaScript and return the aggregated results on-chain using a single smart contract function call.
Additionally, we built a demo with a frontend to show one of the many possible use cases for the Universal Adapter. This demo enables influencers to make trustless social media promotion deals with easy customization.
How it works
The Universal Adapter was created by extending my previous project, Adapter.js, and combining it with a custom on-chain aggregation contract.
The Universal Adapter works by allowing users to provide custom JavaScript code which is executed by every node in a DON. Then, the return values for each node are aggregated and the median result is sent back to the requesting contract using a callback. Nodes receive a base reward for responding to the request and each node with the median answer receives a bonus.
Custom code is sent to all the nodes using IPFS, which eliminates on-chain gas storage costs. When a request is sent to the Universal Adapter, it includes a content id hash which is used by each node to fetch the JavaScript file from decentralized storage.
Private variables can be sent to each DON node prior to making an on-chain. These private variables are stored in each node’s independent encrypted storage and are only accessible by requests made by an approved smart contract address. When the request function is called, it passes a hash of the private variables as a reference, so the DON nodes know which private variables to use.
Since every node will have a copy of these private values, this feature should not be used to store high value secrets such as private wallets, but can be used to store less sensitive data like API keys. Additionally, strategies such as giving each node a separate API key and monitoring key usage can mitigate the potential impact of a leaked key.
Private variables are sent to each node’s encrypted storage by having each node host their own isolated HTTPS storage endpoint. This endpoint allows users to upload a private variables object along with the address of the contract authorized to use these variables. It is the responsibility of users to ensure private variables have been successfully uploaded to every node in the network, or their requests may fail. This upload process can be simplified using a script that iterates through the storage endpoints for each node, sends the private variables, and confirms they were successfully saved.
On-chain variables can also be included in a request using a JSON-formatted string. The Universal Adapter then injects any private variables and on-chain variables as global variables in the JavaScript code. This enables flexible use of private values and allows computation to be performed with on-chain values.
All vanilla Node.js code is supported by the Universal Adapter, however it does not offer access to the file system or ability to spawn additional processes. This enables flexibility, while improving the performance and security.
Challenges we ran into
Security was the primary concern during this project. The Universal Adapter tackles security using multiple tools and a defense-in-depth approach.
First, the machines that execute user code are kept on a network isolated from the core Chainlink node and private variable storage. Then, each request is handled by its own resource-restricted container using gVisor, which is an open source tool developed by Google to sandbox containers for its cloud computing products. Finally, within each isolated container, the user-provided code is executed in the VM2 sandbox, which also restricts access to the file system and disables spawning of additional processes. The code is given 30 seconds to return a value before the container is terminated.
Since setting up all the required security infrastructure can be time consuming, this security model can also be achieved by leveraging the existing sandbox infrastructure made available by function-as-a-service (FaaS) platforms like Google Cloud Functions or AWS Lambda.
To further improve security, node operators in a decentralized oracle network can choose to implement a KYC process so that only verified users can deploy contracts that send requests to the Universal Adapter. This would be equivalent to the security model used by all major cloud service providers.
Accomplishments that we're proud of
The first draft of the Universal Adapter v1 is live on the Polygon Mumbai testnet. For a limited time, any user can use it to fetch any data and perform any off-chain computation they please using only testnet LINK.
Furthermore, we were able to deploy an example of how the Universal Adapter may be used to facilitate verification and payment for complex advertising deals with social media influencers. This demonstration shows how the Universal Adapter can be used to enable functionality that was not previously possible on the blockchain.
What we learned
The main takeaway from this project was learning to limit the scope of what to tackle. Since the Universal Adapter seeks to encapsulate the functionality of a web browser and put it on the blockchain in a trustless manner, the scope of possible demonstrations was extremely large. I believe we were able to demonstrate the core functionality we intended without adding unnecessary complexity in the short time allotted.
What's next for The Universal Adapter
I would like to keep working on the Universal Adapter so that it can become a widely used protocol for getting verified data from the internet onto the blockchain. I would also like to seek funding for the server costs associated with my continued development of the project. Universal off-chain computation offers limitless potential for smart contracts and I would like to do whatever I can to make it a reality in the Web3 ecosystem.

Log in or sign up for Devpost to join the conversation.