On-Chain Oracle (Ethereum)

Our API can be consumed via a Chainlink oracle on-chain, on Ethreum. Both Solana NFT and Ethereum NFT prices can be consumed, which means you can build a cross-chain app on Ethereum that, for example, relies on SMB or DeGods prices from Solana.

Setting up the Oracle

Chainlink oracles on Ethereum require one to operate a node in order to access an endpoint. At this point Tensor doesn't have its own node, which means (for now) the responsibility falls onto the consumer.

The good news is that there are "Node-as-a-service" services that are actually free on test networks like Rinkeby and Goeli, and are super easy to setup.

  • Head on over to https://naas.link/

  • Sign up then hit "Deploy". This will take you to https://naas.link/nodes where you can select your network and deploy a node. For this tutorial we'll be deploying a Rinkeby node

When deploying the node you'll be given credentials in the following format - be sure to save them down! You won't get access to them again.

Domain login

Username: [email protected]

Password: 307ba64T25qKepO198tUz

Node ui login

Username: [email protected]

Password: bpjrC09T1n7F8AD56giu3

  • Once your node is live hit the blue "Operator" button on the right hand side

  • You'll be taken to https://xxx.eu-west1.naas.linkpool.io/. Use the "domain login" details to get rid of the browser password prompt, then login into the actual page using "node ui login"

  • Once inside, we'll need to fund your node.

    • Hit the settings cog in the upper right corner, then find the public key of your node under "Account addresses". Mine looks like this: 0xD0cf91f226c625187Ed20AF82B482669aa78fcAE

    • Let's get some test ETH and LINK. Chainlink conveniently has a faucet for different networks. Fill out the details and wait for your ETH and LINK to arrive.

    • Once done, send 50% of both to the node address above.

    • Our node is now funded!

  • Next you'll need to complete 3 sections from Chainlink's own tutorial:

The key you want to put into the job is the key of your Oracle - NOT the key of your node. So NOT the key you sent funds to before.

  • To recap, what we've done so far is:

    • We've deployed our own node & funded it. This is the actual hardware that will be fulfilling the job.

    • We've deployed our contract & enabled the node on the contract. Our contract will now forward the job to the node.

    • We've created a generic job that can fulfill HTTP requests on that node. We'll be hitting it next.

Testing the Oracle

Now the fun part! Let's actually use the oracle!

  • Go to our chainlink example repo and copy the code from here.

  • Go to remix and create a new workspace/contract - paste the code from the repo into it

  • Click into the compile tab, and hit "Compile", if not done automatically

  • Click into the deployment tab, change your environment to "Injected Web3" (make sure the network is the correct one - should be eg 4 for Rinkeby)

  • Select BaycPriceFetched from the contract menu and hit deploy

  • Since Chainlink isn't free, our consumer contract will have to pay our provider contract (that we deployed earlier). Therefore we need to fund our consumer contract.

    • Copy the newly deployed contract address. If you're wondering where it is, it's on the left, just below "Deployed Contracts" and looks like this: BAYCPRICEFETCHER AT 0X3A0...A1E7B

    • Send the remaining 5 LINK to it & wait for the transaction to confirm

    • Our consumer is funded!

Don't forget to fund the consumer. Without funding your request transactions will fail!

  • Once funded, click on getBAYCPrice on the left and fill out the fields.

    • _oracle = your oracle address

    • _jobId = your job ID WITHOUT DASHES, mine looks like this 6be38109f4464658b2fc5fff40dd973b

  • Hit transact!

  • After the transaction confirms, give it a bit of time (up to a min) and hopefully when you hit the currentPrice field you get a number other than 0! Mine is showing 9879105914415002000000 (price of BAYC in wei)

  • You can repeat the same operation but this time calling getBAYCPriceAt with at set to a unix timestamp such as 1645215894

    • This will update the price on the consumer contract. Note that with current architecture, the contract only stores a single price

  • If you're curious to see more details about the job's execution go over to https://xxx.eu-west1.naas.linkpool.io/jobs, click into the job and explore the previous runs

  • If you're experiencing problems, try reading this section of Chainlink's docs, which describes the same steps above just for a different contract. Replace the code there with the code from our repo and everything should work

And just like that, you can consume smart floor prices on-chain via on oracle!

Happy Ethereum hacking! 🛠

Last updated