Subscribe to esquirebrazy.eth
Subscribe to esquirebrazy.eth
Share Dialog
Share Dialog
<100 subscribers
<100 subscribers
Introduction
Welcome to the RedStone Oracle tutorial! In this guide, we'll walk you through the steps to integrate RedStone Oracle into your decentralized application (Dapp). RedStone Oracle provides a reliable and secure mechanism to fetch on-chain pricing data, making it a valuable tool for DeFi protocols and applications.
Before we begin, make sure you have the following:
Node.js installed
A decentralized application (Dapp) project set up
Basic understanding of Solidity and JavaScript
Start by installing the RedStone EVM Connector library in your project.
yarn add @redstone-finance/evm-connector
npm install @redstone-finance/evm-connector
If you are using Foundry, follow the additional steps mentioned in the installation section of the RedStone Oracle documentation.
Ensure your smart contract code is written in Solidity version 0.8.4 or newer.
Extend one of the RedStone base contracts depending on the data service you intend to use.
// Import the appropriate base contract import "@redstone-finance/evm-connector/contracts/data-services/MainDemoConsumerBase.sol";
contract YourContractName is MainDemoConsumerBase { // Your contract code here }
Remember to pass the data feed ID converted to bytes32 when fetching values.
// Getting a single value uint256 ethPrice = getOracleNumericValueFromTxMsg(bytes32("ETH"));
Now, let's update your Dapp's JavaScript code to interact with RedStone Oracle.
Import the RedStone EVM Connector wrapper code.
const { WrapperBuilder } = require("@redstone-finance/evm-connector");
Wrap your ethers contract with RedStone configuration.
const yourEthersContract = new ethers.Contract(address, abi, provider);
const wrappedContract = WrapperBuilder.wrap(yourEthersContract).usingDataService({ dataFeeds: ["ETH", "BTC"], });
Access your contract's methods as usual.
wrappedContract.executeYourMethod();
For testing in a Hardhat environment, use the mock wrapper to easily override oracle values.
const { SimpleNumericMockWrapper } = require("@redstone-finance/evm-connector/dist/src/wrappers/SimpleMockNumericWrapper");
const wrappedContract = WrapperBuilder.wrap(yourContract).usingSimpleNumericMock({ mockSignersCount: 10, dataPoints: [ { dataFeedId: "ETH", value: 1000 }, ], });
await wrappedContract.yourMethod();
If needed, you can use a manual payload approach. This is helpful for passing pricing data between contracts or when working with Solidity versions below 0.8.4.
Follow the manual payload section in the RedStone Oracle documentation for detailed instructions.
Congratulations! You've successfully integrated RedStone Oracle into your Dapp. Feel free to explore the provided demo and examples in the RedStone Oracle repository for more in-depth understanding.
Now your Dapp can benefit from accurate on-chain pricing data, enhancing its functionality and reliability in the decentralized ecosystem. Happy coding!
Introduction
Welcome to the RedStone Oracle tutorial! In this guide, we'll walk you through the steps to integrate RedStone Oracle into your decentralized application (Dapp). RedStone Oracle provides a reliable and secure mechanism to fetch on-chain pricing data, making it a valuable tool for DeFi protocols and applications.
Before we begin, make sure you have the following:
Node.js installed
A decentralized application (Dapp) project set up
Basic understanding of Solidity and JavaScript
Start by installing the RedStone EVM Connector library in your project.
yarn add @redstone-finance/evm-connector
npm install @redstone-finance/evm-connector
If you are using Foundry, follow the additional steps mentioned in the installation section of the RedStone Oracle documentation.
Ensure your smart contract code is written in Solidity version 0.8.4 or newer.
Extend one of the RedStone base contracts depending on the data service you intend to use.
// Import the appropriate base contract import "@redstone-finance/evm-connector/contracts/data-services/MainDemoConsumerBase.sol";
contract YourContractName is MainDemoConsumerBase { // Your contract code here }
Remember to pass the data feed ID converted to bytes32 when fetching values.
// Getting a single value uint256 ethPrice = getOracleNumericValueFromTxMsg(bytes32("ETH"));
Now, let's update your Dapp's JavaScript code to interact with RedStone Oracle.
Import the RedStone EVM Connector wrapper code.
const { WrapperBuilder } = require("@redstone-finance/evm-connector");
Wrap your ethers contract with RedStone configuration.
const yourEthersContract = new ethers.Contract(address, abi, provider);
const wrappedContract = WrapperBuilder.wrap(yourEthersContract).usingDataService({ dataFeeds: ["ETH", "BTC"], });
Access your contract's methods as usual.
wrappedContract.executeYourMethod();
For testing in a Hardhat environment, use the mock wrapper to easily override oracle values.
const { SimpleNumericMockWrapper } = require("@redstone-finance/evm-connector/dist/src/wrappers/SimpleMockNumericWrapper");
const wrappedContract = WrapperBuilder.wrap(yourContract).usingSimpleNumericMock({ mockSignersCount: 10, dataPoints: [ { dataFeedId: "ETH", value: 1000 }, ], });
await wrappedContract.yourMethod();
If needed, you can use a manual payload approach. This is helpful for passing pricing data between contracts or when working with Solidity versions below 0.8.4.
Follow the manual payload section in the RedStone Oracle documentation for detailed instructions.
Congratulations! You've successfully integrated RedStone Oracle into your Dapp. Feel free to explore the provided demo and examples in the RedStone Oracle repository for more in-depth understanding.
Now your Dapp can benefit from accurate on-chain pricing data, enhancing its functionality and reliability in the decentralized ecosystem. Happy coding!
No activity yet