From Ethereum to Bitcoin: Smart Contract Development on Rootstock
2024-7-18 08:55:43 Author: hackernoon.com(查看原文) 阅读量:2 收藏

Are you a smart contract developer on Ethereum? If yes, you can now develop a smart contract on Bitcoin with the tools you already know using Rootstock. In this tutorial, we will be using Ethereum-related tools to create and deploy smart contracts on Rootstock.

Prerequisites

  • Web browser
  • Metamask Wallet

What Is Rootstock?

Rootstock is an EVM-compatible chain, merging the benefits of Bitcoin with the benefits of Ethereum. The beautiful part is Rootstock has a token called RBTC which is equal to BTC. Being an EVM-compatible chain, it lowers development barriers because tools used in an EVM-compatible chain can also be used at Rootstock.

Since it is an EVM chain, we will be using ChainList to add Rootstock to Metamask

  1. Visit ChainList EVM Filtered link where Rootstock has been searched in networks.

  2. Make sure Include Testnets is checked.

  3. Click on the connect wallet button; this will pop up a Metamask modal to connect to ChainList.

ChainList showing rootstock as search network with Testnets included

Clicking on Connect Wallet changed the Connect Wallet to Add to Metamask

  1. Click Add to Metamask for Rootstock Mainnet.

  2. Click Add to Metamask for Rootstock Testnet; this popup is a modal by Metamask to approve and later switch the network.

ChainList With Metamask connected

Getting Rootstock Testnet Native Token (tRBTC)

  1. Visit Rootstock faucet, and copy and paste your Metamask wallet address.

  2. Check the I'm not a robot,

  3. Click the Get test RBTC button. After a few seconds, check your wallet, and you will see the balance.

Rootstock Faucet

Checking Your First Transaction on Testnet Explorer

Visit Rootstock Testnet Explorer at explorer.testnet.rootstock.io, enter your wallet address, and press enter key to search. The Testnet faucet transaction is shown in the screenshot below.

Rootstock testnet explorer

Writing First Smart Contract Using Remix

We will be using the Remix IDE to write our first smart contract.

  1. Visit https://remix.ethereum.org/

  2. Create a new file called SimpleStorage.sol.

  3. Copy and paste the code below in the newly created SimpleStorage.sol file.

// SPDX-License-Identifier: MIT
// compiler version must be greater than or equal to 0.8.24 and less than 0.9.0
pragma solidity ^0.8.24;

contract SimpleStorage {
    uint storedData;
    function set(uint x) public {
        storedData = x;
    }
    function get() public view returns (uint) {
        return storedData;
    }
}

Compile SimpleStorage.sol on Remix

  1. Click on the Solidity logo Icon by the left menu.

  2. Check the Auto compile.

  3. Click the Compile SimpleStorage button.

Remix Compile SimpleStorage.sol Smart Contract

Deploying the Smart Contract on Rootstock

In your MetaMask switch your MetaMask network to Rootstock Testnet.

  1. Click the deploy & run transaction button.

  2. Select Inject Provider - MetaMask.

  3. Make sure the account you select the account with balance.

  4. Select the smart contract in this example SimpleStorage.

  5. Click the Deploy button.

Deploying Smart Contract on Rootstock

Interacting with SimpleStorage Smart Contract

Verifying Smart Contract Transaction on Rootstock Testnet Explorer

  1. Visit explorer.testnet.rootstock.io

  2. Copy your smart contract address, and paste the address into the search input; press enter to search

SimpleStorage contract deployed showed on Rootstock Testnet

What Next?

All the tools and languages used on Ethereum are compatible with Bitcoin thanks to Rootstock, you can now port your favorite Ethereum protocol to Bitcoin. Take your learning to the next level at https://dev.rootstock.io/


文章来源: https://hackernoon.com/from-ethereum-to-bitcoin-smart-contract-development-on-rootstock?source=rss
如有侵权请联系:admin#unsafe.sh