Introduction
Welcome to the comprehensive tutorial on integrating RedStone Oracles into a zkSync-powered decentralized application (dApp). This guide will walk you through the step-by-step process of enhancing your decentralized marketplace with accurate and reliable price data from RedStone Oracles.
In this tutorial, we'll cover the integration of RedStone Oracles into both the smart contracts and TypeScript code of your zkSync-based dApp. RedStone Oracles provide secure and decentralized access to real-world data, enriching your decentralized marketplace with up-to-date and trustworthy pricing information.
Whether you're a seasoned blockchain developer or just starting your journey into decentralized applications, this tutorial is designed to be accessible and informative. By the end, you'll have a zkSync-powered dApp that leverages RedStone Oracles for precise pricing, providing a seamless experience for users interacting with your decentralized marketplace.
Let's dive into the integration process, ensuring your dApp is equipped with the power of RedStone Oracles to enhance the reliability and functionality of your decentralized ecosystem.
Steps to go through

Prepare Repository:
1. Clone the RedStone
stable-price-marketplace repository:
git clone https://github.com/redstone-finance/stable-price-marketplace
cd stable-price-marketplace
2. Install dependencies:
yarn install
3.Run local zkSync node (Follow instructions in the provided link).
Get Familiar with the Code:
Read the implementation description in the repository.
Integrate with RedStone Oracles:
1. Adjust Smart Contract:
Modify the StableMarketplace contract. It should extend MainDemoConsumerBase and override _getPriceFromOrder. Use getOracleNumericValueFromTxMsg to fetch RedStone price data.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@redstone-finance/evm-connector/contracts/data-services/MainDemoConsumerBase.sol";
import "./Marketplace.sol";
contract StableMarketplace is Marketplace, MainDemoConsumerBase {
function _getPriceFromOrder(SellOrder memory order) internal view override returns (uint256) {
uint256 ethPrice = getOracleNumericValueFromTxMsg(bytes32("ETH"));
return (order.price / ethPrice) * (10 ** 8);
}
}
2. Adjust dApp TypeScript Code:
In blockchain.ts, implement the buy function, wrapping the contract instance with RedStone framework.
import { WrapperBuilder } from "@redstone-finance/evm-connector";
async function buy(orderId) {
const marketplace = await getContractInstance("marketplace");
try {
const wrappedMarketplaceContract = WrapperBuilder.wrap(marketplace).usingDataService({
dataServiceId: "redstone-main-demo",
uniqueSignersCount: 1,
dataFeeds: ["ETH"],
});
const expectedEthAmount = await wrappedMarketplaceContract.getPrice(orderId);
const buyTx = await wrappedMarketplaceContract.wi(orderId, {
value: expectedEthAmount.mul(101).div(100),
});
await buyTx.wait();
return buyTx;
} catch {
const errText = "Error happened while buying the NFT";
alert(errText);
}
}
Test dApp Locally:
1. Check if tests pass
yarn test
2. Compile contracts
yarn compile
3. Deploy contracts on the local blockchain (populate .env file with private key)
yarn deploy:local
4.Run the React app
yarn app:start
Conclusion
Congratulations on completing the tutorial on integrating RedStone Oracles into your zkSync-powered decentralized application! By incorporating RedStone's secure and decentralized price data, your decentralized marketplace is now equipped with reliable information, enhancing user experience and trust.
Throughout this guide, you've learned how to adjust smart contracts to fetch RedStone price data and adapt TypeScript code to seamlessly integrate with the RedStone framework. This integration not only enriches your dApp with real-world pricing accuracy but also showcases the potential of combining zkSync's scalability with RedStone's decentralized data services.
As you explore the finalized implementation, you've gained valuable insights into leveraging RedStone Oracles for precise pricing within the context of a decentralized marketplace. Feel free to adapt and extend this knowledge to further enhance your blockchain projects.
Thank you for investing your time in this tutorial. We hope this integration contributes to the success and effectiveness of your zkSync-based decentralized application. Happy coding!
This is all for today see you next time use the following links to join, reach us and learn more