# Contract Deployment

## Matchain Development Guide

Already know what you're doing?

* Add Matchain
* RPC URL: [https://rpc.matchain.io](https://rpc.matchain.io/), access archives at <https://matchain-mainnet-archive.alt.technology> (tx blocks more than 2350000 behind current newest block cannot be indexed)
* ChainID: 698
* Bridge or request gas sponsorship from our team

### 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:

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

   ```bash
   npx hardhat init
   ```

   Follow the prompts to set up your project.
3. Configure Hardhat to use Matchain by updating `hardhat.config.js`:

   ```javascript
   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`:

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

   ```bash
   npx hardhat compile
   ```
6. Deploy your contract to Matchain:

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

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

   ```javascript
   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](https://remix.ethereum.org/).
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:

   ```solidity
   // 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!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.matchain.io/development/contract-deployment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
