π¬Pythia: automation
Pythia is a flexible automation oracle capable of executing transactions at scheduled intervals, providing randomness, or delivering price feeds from Sybil. This guide will walk you through the process of creating a subscription using both the front-end application and Solidity.
Frontend Subscribe
For frontend subscription, follow these steps:
Visit the Pythia application page at Pythia DApp.
Set up your own subscription by choosing the chain where your contract resides, specifying your contract address, and defining the method to be executed.
Define the automation frequency, and if desired, add payload to execution transactions as randomness or price feed from Sybil.
Authenticate with Self Identity Wallet Extension (SIWE), top up your execution wallet, and submit your subscription.
You can also create a subscription through Solidity using the OrallyPythiaSubscriptionsRegistry contract. Here's the contract's interface:
interface IOrallyPythiaSubscriptionsRegistry {
function subscribe(
address target,
string calldata method,
uint256 frequency,
bool is_random,
string calldata pair_id
) external;
function unsubscribe(uint256 subscription_id) external;
}Subscription Usage Examples
Here are a few examples demonstrating how to use the Pythia subscription in different scenarios:
Basic Execution: An example where the Pythia oracle executes a simple update to a value.
import {OrallyPythiaConsumer} from "../consumers/OrallyPythiaConsumer.sol";
contract PythiaExecutionExample is OrallyPythiaConsumer {
uint256 public value;
constructor(
address _pythiaRegistry
) OrallyPythiaConsumer(_pythiaRegistry) {}
function updateValue(uint256 _value) external onlyExecutor {
value = _value;
}
}Raffle: In this scenario, Pythia is used to randomly pick a raffle winner.
import {OrallyPythiaConsumer} from "../consumers/OrallyPythiaConsumer.sol";
contract RaffleExample is OrallyPythiaConsumer {
uint256 maxNumberOfTickets;
uint256 ticketPrice;
address[] entries;
constructor(
address _pythiaRegistry,
uint256 _maxNumberOfTickets,
uint256 _ticketPrice
) OrallyPythiaConsumer(_pythiaRegistry) {
maxNumberOfTickets = _maxNumberOfTickets;
ticketPrice = _ticketPrice;
}
function enterRaffle() external payable {
require(
entries.length < maxNumberOfTickets,
"RaffleExample: Raffle is full"
);
require(
msg.value == ticketPrice,
"RaffleExample: Ticket price is not correct"
);
entries.push(msg.sender);
}
function pickWinner(uint256 _randomNumber) external onlyExecutor {
require(
entries.length == maxNumberOfTickets,
"RaffleExample: Raffle is not full"
);
uint256 winnerIndex = _randomNumber % entries.length;
payable(entries[winnerIndex]).call{value: address(this).balance}("");
}
}Price Feed: This example demonstrates how Pythia can be used to regularly update a price feed using data from Sybil.
These examples should help you get started with using Pythia. With its robust features, Pythia offers great flexibility in automating transactions and retrieving real-time data, making it a vital tool for any decentralized application.
Last updated