Contract Deployment

Matchain Development Guide

Already know what you're doing?

Hardhat

Hardhat is a development environment for Ethereum-based smart contracts, providing tools for compilation, deployment, testing, and debugging.

Getting Started with Hardhat

  1. Install Hardhat:

    npm install --save-dev hardhat
  2. Create a new Hardhat project:

    npx hardhat init

    Follow the prompts to set up your project.

  3. Configure Hardhat to use Matchain by updating hardhat.config.js:

    module.exports = {
      solidity: "0.8.17",
      networks: {
        matchain: {
          url: "https://rpc.matchain.io",
          chainId: 698,
          accounts: ["YOUR_PRIVATE_KEY"] // Replace with your wallet's private key
        }
      }
    };
  4. Write your smart contract in the contracts folder, e.g., HelloWorld.sol:

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.17;
    contract HelloWorld {
        string public greet = "Hello World!";
    }
  5. Compile your contract:

    npx hardhat compile
  6. Deploy your contract to Matchain:

    npx hardhat run scripts/deploy.js --network matchain

    Ensure you have a deployment script in the scripts folder, e.g., deploy.js:

    async function main() {
        const HelloWorld = await ethers.getContractFactory("HelloWorld");
        const helloWorld = await HelloWorld.deploy();
        await helloWorld.deployed();
        console.log("Contract deployed to:", helloWorld.address);
    }
    main().catch((error) => {
        console.error(error);
        process.exitCode = 1;
    });

Danger! It is very dangerous to use a wallet with valuable assets for development. You could easily write code with a bug that transfers the wrong amount of the wrong token to the wrong address. Transactions cannot be reversed once sent! -> Be safe and use separate wallets for separate purposes.

Remix

What is Remix?

Remix Project is a robust set of tools that can be used by individuals of any skill level throughout the entire process of developing contracts, and it also serves as an educational platform for learning and experimenting with Ethereum.

Getting Started with Remix

  1. Visit Remix.

  2. Navigate to the File Explorer and click the contract button in the top left to create a Smart Contract.

  3. Enter a name for the contract, e.g., test.sol.

  4. Input your smart contract or use the sample contract below:

    // SPDX-License-Identifier: MIT
    // compiler version must be greater than or equal to 0.8.17 and less than 0.9.0
    pragma solidity ^0.8.17;
    contract HelloWorld {
        string public greet = "Hello World!";
    }
  5. Navigate to the Solidity Compiler sidebar option and click "Compile."

If you didn't get any errors, let's proceed with deploying it onto the blockchain. But first: Danger! It is very dangerous to use a wallet with valuable assets for development. You could easily write code with a bug that transfers the wrong amount of the wrong token to the wrong address. Transactions cannot be reversed once sent! -> Be safe and use separate wallets for separate purposes.

Deploying Your Smart Contract

Once you have written your Smart Contract in Remix, you can navigate to the sidebar option to Compile your contract.

  1. Navigate to the "Deploy & run transactions" sidebar option.

  2. Change the top ENVIRONMENT dropdown from "Remix VM" to "Injected Web3."

  3. This will prompt MetaMask - Press "Connect" in MetaMask to allow Remix access.

  4. Click the "Deploy" button, and confirm the transaction in MetaMask.

  5. Deploy done!

Congratulations, you've deployed your first contract on Matchain!

Last updated

Was this helpful?