\
:::info This story was written using HackerNoon’s writing prompt for the Bitcoin Writing Contest. If you’d like to participate in the #bitcoin writing contest but feel this template isn’t right for you, feel free to explore any of the other two options:
:::
\
1. What is your smart contract designed to do?My hybrid smart contract is designed to tap into Chainlink's Price Feeds on Rootstock to get real-world asset prices. This is particularly useful if you're building DeFi applications that need reliable price data.
2. Why deploy on Roostock, what benefits does the platform offer compared to alternatives?Because Rootstock, being merge-mined with Bitcoin, inherits its unparalleled security model while maintaining full EVM compatibility. This means I can leverage the entire Ethereum development ecosystem while building on Bitcoin's foundation. Moreover, if also add Chainlink's oracle network to the mix, I suddenly have the ability to create a smart contract that can interact with real-world data and systems.
3. Break down the key components of your smart contract i.e state variables, functions, events, etc Smart ContractRootStockPriceFeed.sol
SPDX-License-Identifier: MIT
Imports State Variables Constructor Functions Key PointsThis is a proof-of-concept(POC) and since I am using the Chainlink battle-tested AggregatorV3Interface.sol contract but with no offical price feed contract address for RootStock on Chainlink https://docs.chain.link/data-feeds/price-feeds/addresses, I tested my RootStockPriceFeed.sol using a depolyment script to do a staging test on the RSK Testnet using my own public address “0xEd752dCE9f6c1Db35FeDABca445617A0d2B0b674”
\
5. What steps have you taken to keep your smart contract safe?Eventhough there was no need to do an official audit of my POC, I used one of the most popular static analysis tools to do an audit to ensure safety of my hybrid smart contract using: Slither.
\ The output color codes potential issues:
\
\
6. Share, step-by-step, how you deployed your smart contract on Rootstock.Before we dive into the technical details, make sure you have Node.js and nvm version manager for node.js installed on your system since we'll need it to install and use Node version v18.0.0 that is compatible with Rootstock starter kit. You'll also need Hardhat and a basic grasp of smart contracts with Solidity and JavaScript/TypeScript. You'll also need a Metamask wallet configured for the Rootstock network and some test RBTC if you're planning to follow along.
\ Let's start by setting up our development environment. First, we'll clone the Rootstock Hardhat Starter Kit, which provides a solid foundation for our project:
Now, let's install all the required dependencies:
Let's rename our project directory to better reflect its purpose:
We'll need to modify our package.json and package-lock.json to reflect our project's new name and add Chainlink specific dependencies:
After installation, add the plugin to your Hardhat config:
The magic happens in our configuration setup. We need to tell Hardhat how to work with both Rootstock and Chainlink. I've found that keeping this configuration clean and well-organized saves countless hours down the line. Update your hardhat.config.ts file:
Don't forget to create a .env file to store your sensitive information:
Next, let's test our RootStock configuration, but first make sure you have sufficient Testnet RBTC funds available on your Metamask wallet. You can get some from a Rootstock Testnet Faucet.
\ Then, let's deploy the contract. We'll use the --tags flag to only deploy the MultiToken 1155 contract.
Output:
Next, let's test our Chainlink confirguration to get a list of all available getter-method for a specific registry
Output:
Now, let's build something practical - a smart contract that taps into Chainlink's Price Feeds on Rootstock to get real-world asset prices. This is particularly useful if you're building DeFi applications that need reliable price data. Here's what that looks like:
\
To bring our contract to life, we need a deployment script. Create scripts/deploy.ts:
Finally, let's deploy our hybrid smart contract to the Rootstock RSK Testnet by running the deploy script:
Output:
7. What did you learn from your deployment experience? What worked well, and what would you change the next time around?The magnificence of combining Rootstock with Chainlink through Hardhat is that it opens up a world of possibilities. You're not just building smart contracts; you're given the opportunity to creating secure, Bitcoin-based applications that can interact with real-world data. The security of Bitcoin's network, the flexibility of EVM compatibility, and reliable external data through Chainlink oracles - it's a powerful combination that's greater than the sum of its parts.
\ This simple contract demonstrates how to create a hybrid smart contract that leverages off-chain data (via Chainlink) to provide on-chain functionality (retrieving asset prices) on RootStock.
\ All worked well, with some warnings after a quick audit using Slither static analysis tool and next time around I will do a few changes:
\
\ You can visit my GitHub Repo and check out the POC here: https://github.com/EdwinLiavaa/Rootstock-Chainlink-Hardhat-Starterkit
\ That’s all!
:::info If you’d like to participate in the #bitcoin writing contest but feel this template isn’t right for you, feel free to explore any of the other two options:
:::
\
All Rights Reserved. Copyright , Central Coast Communications, Inc.