Skip to main content
In the previous guide you wrote a simple contract that stores and retrieves an integer. Now you deploy it to peaq. Deployment broadcasts the contract’s bytecode to the chain, which is what makes it callable. This guide covers Remix, Hardhat, and Foundry.

Prerequisites

Instructions

Deploying with Remix

1. Compile the Smart Contract

  • Open the Compile Sidebar in Remix:
    • Select the Solidity Compiler from the left sidebar.
  • Compile the Contract:
    • Ensure the Solidity version matches the pragma directive in your contract (e.g., ^0.8.0).
    • Click the Compile SimpleStorage.sol button.
    • Ensure a green checkmark has appeared after successful compilation.

2. Deploy the Contract

  • Open the Deploy & Run Transactions Sidebar:
    • Select the Deploy & Run Transactions option in the Remix sidebar.
  • Select the Environment:
    • From the Environment dropdown, select Injected Provider - MetaMask.
    • Confirm that MetaMask is connected to the appropriate network by checking the Chain ID.
  • Deploy the Contract:
    • Click the orange Deploy button to initiate the transaction.
    • A MetaMask popup will appear for transaction confirmation. Ensure you have sufficient $AGUNG/$PEAQ tokens in your wallet for gas fees.

3. View Deployment Details

Once the transaction is confirmed, the Remix console will display deployment logs, including:
  • Transaction Hash: Unique identifier for the transaction sent to the blockchain. The hash allows you to track and verify the transaction on the chain. It acts like a deployment receipt. You can use this transaction hash in an explorer to view detailed information about the transaction.
  • Block Number: The number of the block your transaction was included on-chain. Blocks are used to group transactions together and the number is used to indicate where your contract deployment was recorded.
  • Gas Used: The amount of computational effort that the blockchain required to process your transaction. Deploying a contract consumes gas since it involves writing the bytecode on-chain. Gas is used to show how resource-intensive the deployment was.
  • Contract Address: The unique address assigned to your deployed smart contract on the blockchain. This address allows you and other users to interact with your contract. It is the location of the contract on the blockchain network.

Deploying with Hardhat

1. Create a Deployment Script

  • Set Up the Script:
    • In the ignition/modules/ folder, create a file named SimpleStorage.js
  • Add Deployment Logic:
    • Add the following code to deploy your SimpleStorage js file:

2. Deploy the Contract

  • Run the Deployment Command:
    • In your terminal, navigate to the project’s root directory
    • Execute the following command to deploy the contract to the agung test network:
  • View Deployment Output:
    • Upon successful deployment, the terminal will display:
      • Deployed Contract Address: The unique address assigned to your deployed smart contract on the blockchain. Record the contract address for future interactions.

Deploying with Foundry

Use Foundry to deploy using forge create or a script.

1. Prepare environment

Create a .env in your project root with:

2. Deploy with forge create

3. Deploy with a script

Create script/DeploySimpleStorage.s.sol:
Run it:

Gas estimates on agung

If gas estimates come back too low on agung, append:

Verify the deployment

Search for your transaction hash or contract address on the peaq or agung block explorer and confirm the contract is there. Once the contract address is valid, continue with Interact with Smart Contract.