Build A Smart Contract

MAGNE Layer1 Blockchain

Deploy Smart Contracts

A guide to help you get started with deploying your smart contracts on MAGNE Layer1 Blockchain.

Welcome to the MAGNE Layer1 Blockchain deployment quickstart guide! This comprehensive walkthrough will help you set up your environment and deploy smart contracts on MAGNE Layer1 Blockchain. Whether you're a seasoned developer or just starting out, this guide has got you covered.

What You'll Achieve

By the end of this quickstart, you'll be able to:

  • Set up your development environment to deploy on MAGNE Layer1 Blockchain
  • Deploy your smart contracts to MAGNE Layer1 Blockchain
  • Connect your frontend to your smart contracts
  • Why MAGNE Layer1 Blockchain?

MAGNE Layer1 Blockchain is a mobile-first, EVM-compatible, PoW-based Layer1 chain where smartphones and edge devices can participate in mining and consensus, ensuring security, decentralization, and performance.

Set Up Your Development Environment

  1. Create a new project directory
mkdir my-MAGNE-project && cd my-MAGNE-project
  1. Install Foundry, a powerful framework for smart contract development
curl -L https://foundry.paradigm.xyz | bash
foundryup

This installs Foundry and updates it to the latest version.

  1. Initialize a new Solidity project

Copy

forge init

Your Foundry project is now ready. You'll find an example contract in the src directory, which you can replace with your own contracts. For the purposes of this guide, we'll use the Counter contract provided in src/Counter.sol

Foundry provides a suite of tools for EVM application development, including Forge (for testing), Cast (for interacting with the chain), and Anvil (for setting up a local node). You can learn more about Foundry here.

Configure Foundry with MAGNE Layer1 Blockchain

To deploy your smart contracts to MAGNE Layer1 Blockchain, you need two key components:

  1. A node connection to interact with the MAGNE Layer1 Blockchain network
  2. A funded private key to deploy the contract

Let's set up both of these:

1. Set up your node connection

  1. Create a .env file in your project's root directory
  2. Add the MagicalHash network RPC URL to your .env file
MAGICAL_RPC_URL="https://rpc.testnet.magicalhash.com"
  1. Load your environment variables
source .env

Magne L1 Testnet is the test network for MAGNE Layer1 Blockchain, which we will use for the rest of this guide. You can obtain free MHA from one of the faucets .

2. Secure your private key

  1. Store your private key in Foundry's secure keystore
cast wallet import deployer --interactive
  1. When prompted enter your private key and a password.

Your private key is stored in ~/.foundry/keystores which is not tracked by git.

Never share or commit your private key. Always keep it secure and handle with care.

Deploy Your Contracts

Now that your environment is set up, let's deploy your contracts to Magne L1 Testnet.

  1. Use the following command to compile and deploy your contract
forge create ./src/Counter.sol:Counter --rpc-url $MAGICAL_RPC_URL --account deployer

Note the format of the contract being deployed is <contract-path>:<contract-name>.

  1. After successful deployment, the transaction hash will be printed to the console output
  2. Copy the deployed contract address and add it to your .env file
COUNTER_CONTRACT_ADDRESS="0x..."
  1. Load the new environment variable
source .env

Verify Your Deployment

To ensure your contract was deployed successfully:

  1. Check the transaction on https://explorer.testnet.magicalhash.com.
  2. Use the cast command to interact with your deployed contract from the command line
cast call $COUNTER_CONTRACT_ADDRESS "number()(uint256)" --rpc-url $MAGNE_RPC_URL

This will return the initial value of the Counter contract's number storage variable, which will be 0.

Congratulations! You've deployed your smart contracts to MAGNE L1 chain!

M Hash Layer2 Blockchain

Deploy Smart Contracts

A guide to help you get started with deploying your smart contracts on M Hash Layer2 Blockchain

Welcome to the M Hash Layer2 Blockchain deployment quickstart guide! This comprehensive walkthrough will help you set up your environment and deploy smart contracts on M Hash Layer2 Blockchain. Whether you're a seasoned developer or just starting out, this guide has got you covered.

What You'll Achieve

By the end of this quickstart, you'll be able to:

  • Set up your development environment to deploy on M Hash Layer2 Blockchain.
  • Deploy your smart contracts to M Hash Layer2 Blockchain.
  • Connect your frontend to your smart contracts
  • Why M Hash Layer2 Blockchain?

M Hash Layer2 Blockchain is a high-performance Layer 2 network built on opStack with an asynchronous consensus mechanism, separating consensus from execution to significantly boost throughput and efficiency while ensuring security and low-cost transactions.

Set Up Your Development Environment

  1. Create a new project directory
mkdir my-MAGNE-project && cd my-MAGNE-project
  1. Install Foundry, a powerful framework for smart contract development
curl -L https://foundry.paradigm.xyz | bash
foundryup

This installs Foundry and updates it to the latest version.

  1. Initialize a new Solidity project
forge init

Your Foundry project is now ready. You'll find an example contract in the src directory, which you can replace with your own contracts. For the purposes of this guide, we'll use the Counter contract provided in src/Counter.sol

Foundry provides a suite of tools for EVM application development, including Forge (for testing), Cast (for interacting with the chain), and Anvil (for setting up a local node). You can learn more about Foundry here.

Configure Foundry with M Hash Layer2 Blockchain

To deploy your smart contracts to M Hash Layer2 Blockchain, you need two key components:

  1. A node connection to interact with the M Hash Layer2 Blockchain network
  2. A funded private key to deploy the contract

Let's set up both of these:

1. Set up your node connection

  1. Create a .env file in your project's root directory
  2. Add the M Hash Layer2 Blockchain network RPC URL to your .env file
MAGICAL_RPC_URL="https://l2-rpc.testnet.magicalhash.com"
  1. Load your environment variables
source .env

M Hash L2 Testnet is the test network for M Hash Layer2 Blockchain, which we will use for the rest of this guide. You can obtain free MHA from one of the faucets .

2. Secure your private key

  1. Store your private key in Foundry's secure keystore
cast wallet import deployer --interactive
  1. When prompted enter your private key and a password.

Your private key is stored in ~/.foundry/keystores which is not tracked by git.

Never share or commit your private key. Always keep it secure and handle with care.

Deploy Your Contracts

Now that your environment is set up, let's deploy your contracts to M Hash L2 Testnet.

  1. Use the following command to compile and deploy your contract
forge create ./src/Counter.sol:Counter --rpc-url $MAGICAL_RPC_URL --account deployer

Note the format of the contract being deployed is <contract-path>:<contract-name>.

  1. After successful deployment, the transaction hash will be printed to the console output
  2. Copy the deployed contract address and add it to your .env file
COUNTER_CONTRACT_ADDRESS="0x..."
  1. Load the new environment variable
source .env

Verify Your Deployment

To ensure your contract was deployed successfully:

  1. Check the transaction on https://l2-explorer.testnet.magicalhash.com.
  2. Use the cast command to interact with your deployed contract from the command line
cast call $COUNTER_CONTRACT_ADDRESS "number()(uint256)" --rpc-url $MAGNE_RPC_URL

This will return the initial value of the Counter contract's number storage variable, which will be 0.

Congratulations! You've deployed your smart contracts to M Hash L2 chain!