Skip to content

Smart Contract Deployment ​

This guide provides an overview of deploying smart contracts on IOST 3.0's Layer 2 platform.

Prerequisites ​

Before deploying contracts to IOST 3.0 Layer 2, ensure you have:

  • Basic understanding of Solidity (for EVM contracts)
  • MetaMask wallet configured for IOST Layer 2
  • Access to Remix IDE or other development environments

Contract Development Overview ​

IOST 3.0 supports EVM-compatible smart contracts, allowing you to use standard Solidity development practices. You can create contracts for various use cases including tokens, NFTs, DeFi applications, and more.

Example Contracts ​

Below are some example contracts that you can deploy on IOST 3.0 Layer 2:

Simple Storage Contract ​

This basic example demonstrates how to store and retrieve a value on the blockchain:

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

contract SimpleStorage {
    uint256 private storedValue;
    
    event ValueChanged(uint256 newValue);
    
    function set(uint256 value) public {
        storedValue = value;
        emit ValueChanged(value);
    }
    
    function get() public view returns (uint256) {
        return storedValue;
    }

ERC-20 Token Contract ​

A standard ERC-20 token implementation using OpenZeppelin contracts:

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

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

contract IOSTToken is ERC20, Ownable {
    constructor(uint256 initialSupply) ERC20("IOST Example Token", "IET") {
        _mint(msg.sender, initialSupply);
    }
    
    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}

NFT Collection Contract ​

A simple NFT collection using ERC-721 standard:

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

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract IOSTCollection is ERC721URIStorage, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
    
    constructor() ERC721("IOST NFT Collection", "IOSTNFT") {}
    
    function mintNFT(address recipient, string memory tokenURI) public onlyOwner returns (uint256) {
        _tokenIds.increment();
        
        uint256 newItemId = _tokenIds.current();
        _mint(recipient, newItemId);
        _setTokenURI(newItemId, tokenURI);
        
        return newItemId;
    }
}

Deployment Process ​

1

Write Contract

Create Solidity smart contract

→
2

Compile

Generate bytecode and ABI

→
3

Deploy

Submit to IOST Layer 2

→
4

Verify

Confirm successful deployment

Using Remix IDE ​

Remix IDE provides a simple way to develop and deploy contracts:

  1. Open Remix IDE
  2. Create and compile your Solidity contract
  3. Go to "Deploy & Run Transactions" tab
  4. Select "Injected Provider - MetaMask" from Environment dropdown
  5. Connect your MetaMask wallet configured for IOST Layer 2
  6. Deploy your contract and confirm the transaction in MetaMask

Using Hardhat ​

For more advanced development workflows:

  1. Set up a Hardhat project with appropriate network configuration
  2. Create deployment scripts
  3. Execute deployment to IOST Layer 2
  4. Verify contract deployment
solidity
// hardhat.config.js example for IOST Layer 2
require("@nomiclabs/hardhat-waffle");
require("dotenv").config();

module.exports = {
  solidity: "0.8.9",
  networks: {
    iost_layer2: {
      url: "https://l2-mainnet.iost.io",
      chainId: 182,
      accounts: [`0x${process.env.PRIVATE_KEY}`],
      gasPrice: 5000000000  // 5 gwei
    }
  }
};

// scripts/deploy.js example
async function main() {
  // Get contract factory
  const StorageFactory = await ethers.getContractFactory("SimpleStorage");
  
  console.log("Deploying contract...");
  // Deploy contract
  const storageContract = await StorageFactory.deploy();
  await storageContract.deployed();
  
  console.log(`Contract deployed to: ${storageContract.address}`);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

Deploy using:

bash
npx hardhat run scripts/deploy.js --network iost_layer2

Contract Verification ​

After deployment, verify your contract on the IOST 3.0 explorer:

  1. Visit the IOST Explorer
  2. Search for your contract address
  3. Follow the verification process to make your contract's source code visible

Contract Interaction ​

Interact with your deployed contracts through:

  • Remix IDE (for simple interactions)
  • Custom dApp frontends
  • Contract Explorer interface
  • Direct MetaMask transactions

Best Practices ​

  • Thoroughly test your contracts before deployment
  • Implement appropriate security measures
  • Document your contract's functions and usage
  • Consider gas optimization techniques
  • Use established patterns and libraries when possible

Troubleshooting ​

Transaction Failures

Symptom: Contract deployment transaction fails

Solution: Check gas settings and wallet balance

Contract Errors

Symptom: Contract functions don't work as expected

Solution: Verify contract logic and test thoroughly

Advanced Development Tools ​

For developers seeking specialized deployment and verification approaches, we offer dedicated guides for popular development frameworks:

Released under the MIT License.