> For the complete documentation index, see [llms.txt](https://docs.studio-blockchain.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.studio-blockchain.com/developers/smart-contract-development.md).

# Smart Contract Development

### **Introduction**

Building and deploying smart contracts on Studio Blockchain is seamless and compatible with Ethereum development tools. This guide will walk you through:

1. Setting up your development environment.
2. Writing and compiling your smart contract.
3. Deploying and verifying your contract on Studio Blockchain.

***

### **1. Setting Up Your Environment**

To develop smart contracts for Studio Blockchain, ensure you have the following tools installed:

#### **Required Tools**

1. **MetaMask Wallet:** To connect to the Studio Blockchain Testnet.
2. **Remix IDE:** A browser-based IDE for writing, compiling, and deploying contracts. Access it here.
3. **Solidity Compiler:** Built into Remix or available via `solc`.
4. **Optional Tools:**
   * **Truffle** or **Hardhat** for advanced workflows.
   * Node.js for dependency management.

***

### **2. Writing Your Smart Contract**

#### **Sample ERC-20 Token Contract**

Here’s a simple ERC-20 token contract example:

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

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

contract MyToken is ERC20 {
    constructor() ERC20("MyToken", "MTK") {
        _mint(msg.sender, 1000000 * (10 ** decimals()));
    }
}
```

#### **Using OpenZeppelin Libraries**

* Studio Blockchain supports widely used Solidity libraries like OpenZeppelin.
* Install dependencies via npm (`npm install @openzeppelin/contracts`) or import directly in Remix.

***

### **3. Compiling Your Contract**

When compiling in Remix IDE:

1. Select the **Solidity Compiler** tab.
2. Choose a version **0.8.0 or higher.**
3. Set the **EVM Version** to one of the following (recommended for Studio Blockchain):
   * **PARIS**
   * **LONDON**
   * **BERLIN**
4. Enable **Optimizations**:
   * Set the **Optimizer Runs** to **200** for gas-efficient deployment.

#### **Compiler Warnings**

If you encounter warnings during compilation:

* Verify the EVM version and optimization settings.
* Ensure all imported libraries are compatible with the selected Solidity version.

***

### **4. Deploying Your Contract**

#### **Using Remix**

1. **Select Deployment Environment:**
   * Open the **Deploy & Run Transactions** tab in Remix.
   * Choose **Injected Web3** as the environment (connects to MetaMask).
2. **Connect to Studio Testnet:**
   * Ensure MetaMask is set to the Studio Blockchain Testnet.
3. **Deploy:**
   * Click **Deploy** and confirm the transaction in MetaMask.
4. **Verify Deployment:**
   * Copy the deployed contract address.
   * Check the contract on [StudioScan](https://studio-scan.com) under the **Contracts** section.

***

### **5. Verifying Your Contract on StudioScan**

Studio Blockchain supports on-chain contract verification to enhance transparency and trust.

#### **Steps for Verification**

1. Go to the StudioScan Contract Verification Page.
2. Enter the following details:
   * Contract Address
   * Solidity Compiler Version
   * EVM Version (e.g., PARIS, LONDON, or BERLIN)
   * Constructor Arguments (if any)
3. Upload the contract source code.
4. Click **Verify** to complete the process.

***

### **6. Best Practices**

1. **Gas Optimization:**
   * Always enable optimizations with 200 runs during compilation.
   * Monitor gas usage via StudioScan’s transaction logs.
2. **Testing:**
   * Use test frameworks like Hardhat or Truffle for unit testing before deployment.
   * Test your contract interactions on the testnet using free STO tokens from the faucet.
3. **Security:**
   * Use tools like Slither or MythX to analyze your smart contract for vulnerabilities.
   * Follow secure coding practices, such as input validation and reentrancy checks.

***

### **Next Steps**

Once your contract is deployed and verified:

1. Interact with it using tools like Remix or CLI commands.
2. Monitor its activity on StudioScan.
3. Proceed to the **Interacting via CLI** subpage to explore advanced contract interactions.
