Developing Smart Contracts

Celestium is fully Ethereum Virtual Machine (EVM)-compatible, allowing developers to write and deploy smart contracts using Solidity, the most popular language for smart contract development. Any contract written for Ethereum can be deployed on Celestium without modification.

This section provides an overview of the smart contract development process and an example of a basic Solidity contract.


Tools for Development

Developers can use familiar Ethereum development tools:

  • Hardhat – Development framework for building and testing smart contracts.

  • Foundry – Fast, modular toolkit for smart contract development.

  • Remix – Online IDE for writing, testing, and deploying Solidity contracts.


Setting Up Hardhat for Celestium

  1. Install Hardhat:

bash
npm install --save-dev hardhat
  1. Create a Hardhat Project:

bash
npx hardhat init
  1. Configure Hardhat for Celestium Testnet:

Modify hardhat.config.js:

javascript

require("@nomicfoundation/hardhat-toolbox");

module.exports = {
  solidity: "0.8.20",
  networks: {
    celestiumTestnet: {
      url: "http://rpc-private-testnet.celestium.network",
      chainId: 252525,
      accounts: [`0x${PRIVATE_KEY}`],
    },
  },
};

Replace PRIVATE_KEY with your wallet's private key.


Example: Simple Solidity Contract

This is a basic contract to store and retrieve a number:

solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract SimpleStorage {
    uint256 private storedNumber;

    function setNumber(uint256 _number) public {
        storedNumber = _number;
    }

    function getNumber() public view returns (uint256) {
        return storedNumber;
    }
}

Deploying the Contract

Create a deployment script scripts/deploy.js:

javascript

const hre = require("hardhat");

async function main() {
  const SimpleStorage = await hre.ethers.getContractFactory("SimpleStorage");
  const simpleStorage = await SimpleStorage.deploy();

  await simpleStorage.waitForDeployment();

  console.log(`Contract deployed to: ${await simpleStorage.getAddress()}`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Run the deployment script:

bash

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

Interacting with the Contract

Once deployed, you can interact with the contract using ethers.js:

javascript

const contractAddress = "DEPLOYED_CONTRACT_ADDRESS";
const SimpleStorage = await ethers.getContractFactory("SimpleStorage");
const simpleStorage = SimpleStorage.attach(contractAddress);

// Set a number
await simpleStorage.setNumber(42);

// Get the number
const storedNumber = await simpleStorage.getNumber();
console.log(`Stored Number: ${storedNumber}`);

Replace DEPLOYED_CONTRACT_ADDRESS with the address of the deployed contract.


Viewing on Explorer

Once deployed, you can verify the contract and track transactions on the Celestium Testnet Explorer.


Best Practices

  • Always test contracts on the Celestium Testnet before deploying on the main network.

  • Use OpenZeppelin Contracts for secure and standardized smart contract implementations.

  • Review gas efficiency and security best practices when writing contracts.

This guide provides the foundation to start developing and deploying smart contracts on Celestium

Last updated