Ir al contenido principal
Time to read: 1 min
Para el índice completo de documentación, consulte llms.txt

Write a Smart Contract

In this section, we'll learn how to write a smart contract using the OpenZeppelin library and Solidity. OpenZeppelin is widely used for its secure, community-vetted, and standardized codebase, which simplifies developing robust and secure smart contracts.

Create a Smart Contract

Step 1: Install OpenZeppelin Contracts

Run the following command to install the OpenZeppelin's library of reusable smart contracts.

    npm install @openzeppelin/contracts

Step 2: Create a Token Contract

  • Navigate to the contracts directory in the root directory of quick start project:
    cd contracts
  • In the contracts directory, open the MyToken.sol file for your token contract:

To configure an ERC20 token, copy the code snippet below and paste it in your token file or view the complete MyToken.sol file on GitHub.

    // SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
_mint(msg.sender, initialSupply);
}
}

This contract defines an ERC20 token named MyToken with the symbol MTK, using OpenZeppelin's ERC20 standard implementation.

Try this contract in Remix

Want to deploy and interact with MyToken.sol without any local setup? Use the button below to open it directly in the Remix IDE. You'll need MetaMask with Rootstock Testnet configured — see the full Remix + Rootstock guide for the exact steps.

Compile the Contract

To build the contract, run the following command in the project's root directory.

npx hardhat compile

This will compile your smart contracts and generate artifacts:

% npx hardhat compile
Downloading compiler 0.8.30
Compiled 6 Solidity files successfully (evm target: paris).

Next

Última actualización en por ahsan-javaiid