# RedStone Oracle Tutorial for Dapp Integration **Published by:** [esquirebrazy.eth](https://paragraph.com/@esquirebrazy/) **Published on:** 2023-12-30 **URL:** https://paragraph.com/@esquirebrazy/redstone-oracle-tutorial-for-dapp-integration ## Content 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.PrerequisitesBefore we begin, make sure you have the following:Node.js installedA decentralized application (Dapp) project set upBasic understanding of Solidity and JavaScriptInstallationStart by installing the RedStone EVM Connector library in your project.Using Yarnyarn add @redstone-finance/evm-connectorUsing NPMnpm install @redstone-finance/evm-connector If you are using Foundry, follow the additional steps mentioned in the installation section of the RedStone Oracle documentation.Adjust Your Smart ContractsEnsure 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"));Adjust JavaScript Code of Your DappNow, 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();TestingFor 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();Manual Payload (Optional)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.ConclusionCongratulations! 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! ## Publication Information - [esquirebrazy.eth](https://paragraph.com/@esquirebrazy/): Publication homepage - [All Posts](https://paragraph.com/@esquirebrazy/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@esquirebrazy): Subscribe to updates