Interaction with JARJAR AI Oracle
Let's build a smart contract that interact with JarJar Oracle
This example show how to generate inference with DALLE-3
jarjar_ai_oracle = "0xf74a927c2fe57604e0dd07907a9f62d74d7b5b1b466381abdbcd0ee18683d125"
As you see your smart contract will need to implement only two function to generate AI
One that need to send prompt and generation data, and the other one (callback function) that will receive the inference result
Let's deep dive in generate function of a dummy smart contract:
To generate and IA inference with your smart contract you need to provide three dynamic field:
prompt_data
callback_data
model_name
All this variable are string, but prompt_data and callback_data are stringified JSON object that the validator will parse to accommodate to the requirement of every model and to bring versatility to the smart contract
You also need 2 non dynamic fields:
price_model :
ownerCap:
Let's see how to call this generate function from TypeScript now:
Stringify your prompt
Stringify your callback_data (callback_data are the parameter that the validator will add when calling your function after generation)
Model name
payment
price_model
ownercap
Let's call the generation function from our smart contract with all this data now
Here it is, you just writed your first onchain smart contact inference 🎉
But how the validator will return you the data ??
The Callback
Here is the validator code that build the callback transaction, as you can see you need in your smart contract a function called callback as this is the one the validator will send the request
Here is an example of Move code to receive the validator callback call
Fisrt this function check that it was called by the owner of the validator to ensure no random people is calling it
Then it simply build and NFT with the callback data and send it back to the user that requested the inference, this is only an example and you could do whatever you want with this data :)
Last updated