See Video Guide for Local Development.
Before running the script, ensure you have the following prerequisites installed:
- Rooch: A blockchain development toolset.
- Node.js: Alongside npm, yarn, or pnpm package managers.
First, you need to have rooch binary in hand. The rooch binary can be downloaded from the Rooch GitHub repo. Use the rooch binary to create a Rooch account. This account will be used throughout the setup process.
rooch initor
rooch account createif there already exists an account.
Clear any existing state and start the local network.
rooch server clean
rooch server startNavigate to this repo's rooch directory, build the contracts for development, and publish them with named addresses and update .env ROOCH_ORACLE_ADDRESS with deployed Address
cd rooch
rooch move publish --named-addresses verity=default,verity_test_foreign_module=default --sender default
cd ..- A sender account is required for deployment and contract updates.
- The account with the upgrade_Cap object can update/upgrade the contract by setting the --sender flag to their account with the upgrade_Cap.
Install the necessary Node.js dependencies using npm, yarn, or pnpm. Ensure you are in the root project directory.
npm install
# or
yarn install
# or
pnpm installRun the Prisma migration to update your database schema according to your models.
In Production (for PostgreSQL):
pnpm clean:db
pnpm prisma:generate
pnpm prisma:deployIn Development (for SQLite):
pnpm clean:db
pnpm prisma:generate:dev
pnpm prisma:deploy:devCopy the example environment file to create your own .env file:
cp .env.sample .envExport the Rooch Private Key:
rooch account export --address <Rooch Address>To connect to the local Rooch node, set ROOCH_CHAIN_ID to "localnet".
Otherwise, connect to testNet by setting ROOCH_CHAIN_ID to "testnet", or to TestNet by setting ROOCH_CHAIN_ID to "testnet".
Ensure that ROOCH_ORACLE_ADDRESS is set to the address of the deployed module, e.g., "0x85859e45551846d9ab8651bb0b6f6e1740c9d758cfda05cfc39d49e2a604d783".
Additional steps for managing supported orchestrator URL
- To add URL
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::registry::add_supported_url --sender-account 0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d --args 'string:https://api.openai.com/v1/chat/completions' --args 'u256:50000' --args 'u64:40' --args 'u256:4000' --args 'u256:5000'- to remove URLs
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::registry::remove_supported_url --sender-account <orchestrator_address> --args 'string:https://api.twitter.com/2/users/'- To view supported URLS
rooch move view --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::registry::get_supported_urls --args 'address:0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d'Start the development server for your application. This step might vary depending on your project setup; the command below assumes a typical setup.
npm run dev
# or
yarn dev
# or
pnpm devFinally, send a new request transaction to have it indexed. Make sure to replace placeholders with actual values relevant to your setup.
rooch move run --function <contractAddress>::example_caller::request_data --sender-account default --args 'string:https://api.x.com/2/users/by/username/elonmusk?user.fields=public_metrics' --args 'string:GET' --args 'string:{}' --args 'string:{}' --args 'string:.data.public_metrics.followers_count' --args 'address:<Orchestrator Address>'Here's an example of requesting the Twitter Followers Count on a Local Rooch Node:
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::example_caller::request_data --sender-account default --args 'string:https://api.x.com/2/users/by/username/elonmusk?user.fields=public_metrics' --args 'string:GET' --args 'string:{}' --args 'string:{}' --args 'string:.data.public_metrics.followers_count' --args 'address:0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d' --args 'u256:50000'or
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::example_caller::request_data --sender-account default --args 'string:https://api.openai.com/v1/chat/completions' --args 'string:POST' --args 'string:{}' --args 'string:{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say this is a test!"}],"temperature": 0.7}' --args 'string:.choices[].message.content' --args 'address:0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d' --args 'u256:50000000'To check the state of the response object on a local Rooch node, use the following command:
rooch state -a /object/0x7a01ddf194f8a1c19212d56f747294352bf2e5cf23e6e10e64937aa1955704b0Additionally, For notification calls you can allocated an portion form escrow for notification per fulfilment Request(Recommended 1Rgas for the first fulfilment).
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::update_notification_gas_allocation --sender-account default --args 'address:0x27e46e033da11c4d1f986081877e80cefb2b29dec1c559c97c3ccf12e910aba7' --args 'string:example_caller::receive_data' --args 'u256:10000000'- To view balance
rooch move view --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::get_user_balance --args 'address:<your_address>'- To withdraw Balance
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::withdraw_from_escrow --args 'u256:<amount>'- To Deposit
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::oracles::deposit_to_escrow --args 'u256:<amount>'To confirm the Request Object State, use the Object ID generated from the initial transaction to query the state of the response object.
This allows you to verify that the request was processed successfully and that the response object is correctly stored in the Rooch Network state.
An example of requesting the Twitter Followers Count on a Rooch Testnet:
rooch move run --function 0xf1290fb0e7e1de7e92e616209fb628970232e85c4c1a264858ff35092e1be231::example_caller::request_data --sender-account default --args 'string:https://api.x.com/2/users/by/username/elonmusk?user.fields=public_metrics' --args 'string:GET' --args 'string:{}' --args 'string:{}' --args 'string:.data.public_metrics.followers_count' --args 'address:0x694cbe655b126e9e6a997e86aaab39e538abf30a8c78669ce23a98740b47b65d'To check the state of the response object on testnet, devnet, or mainnet,
- Switch to the relevant network using
rooch env switch --alias <NETWORK_ALIAS> - Use the following command:
rooch object --object-ids <OBJECT_ID>