Leveraging the compute power of Phala Network on Polkadot, we can bring offchain APIs to any EVM network. This this hack, we call an Youtube API to prediction bet how many views a video will get on Scroll Network
How it Works: We create a TypeScript function, referred to as a "phat" function, that allows us to leverage the computing power of the Phala Network on Polkadot to bring the API call onchain. Building the API Call: We build the API call leveraging Phala Network's pink HTTP request. It will return the response to a set smart contract relayers specified by our RPC settings (that is setup in the phala network interface), in this case, the Scroll Network. Receiving the Message: Once the message is received (listening via events on the block explorer), it will automatically transact to execute the function onchain on the EVM set according to the response received. Example Use Case: For this example, we are taking bets for different ranges of how many views the video would get, and players that choose the right range win the pot when the API is called. We are trying to incentivize users to share out a video to help it get more views to go "viral" with shares as it incentivizes the large "betters" to get paid out.
To get the offchain oracle onchain, https://phala.network/ was used to create the HTTP request and bring the response on chain. Typescript is the language used to create the script for the Phala network to create the response for the request (located in src/index.ts) Phala network interface, helps create the relayer and meta transaction. The smart contract is done in solidity, in which it will send out the requests and wait for the response. In this case, we are requesting a number of views and the number returned onchain is passed through the winner function to pay out the winners that bet in the range. The front end uses the rainbow kit/ wagmi stack with next.js and tailwind.