// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

contract SimpleStorage {

    uint256 favoriteNumber;

    struct People {

        uint256 favoriteNumber;

        string name;

    }

    mapping(string => uint256) public nameToFavNum;

    People[] public people;

    function addPerson(string memory _name, uint256 _favoriteNumber) public {

        people.push(People(_favoriteNumber, _name));

        nameToFavNum[_name] = _favoriteNumber;

    }

    function store(uint256 _favoriteNumber) public virtual {

        favoriteNumber = _favoriteNumber;

    }

    function retrieve() public view returns(uint256){

        return favoriteNumber;

    }

    function add() public pure returns(uint256){

        return 555+1;

    }

}

  • A simple storage variable favoriteNumber.
  • A People struct to store a combination of a favorite number and a name.
  • A mapping nameToFavNum to look up favorite numbers by name.
  • An array of People to store instances of the People struct.
  • Functions like addPerson to add people to the array and update the mapping, store to update the favorite number, retrieve to get the stored favorite number, and add to perform a purely mathematical operation.

Create a deployment script in the scripts folder. For example, you can create a file named deploy.js:

// scripts/deploy.js

async function main() {

  const [deployer] = await ethers.getSigners();

  console.log(`Deploying contracts with the account: ${deployer.address}`);

  // Deploy SimpleStorage contract

  const SimpleStorage = await ethers.getContractFactory(“SimpleStorage”);

  const simpleStorage = await SimpleStorage.deploy();

  console.log(`SimpleStorage address: ${simpleStorage.address}`);

}

main()

  .then(() => process.exit(0))

  .catch((error) => {

    console.error(error);

    process.exit(1);

  });

Step 3: Run the Deployment Script

Execute the deployment script using the following Hardhat command:

npx hardhat run –network mumbai scripts/deploy.js

Make sure to replace mumbai with the network name you defined in your hardhat.config.js.

Step 4: Check the Deployment

After running the script, Hardhat will deploy the SimpleStorage.sol contract to the Mumbai network. The contract’s address will be displayed in the console. You can also check the Mumbai testnet explorer (such as Mumbai Explorer) to verify the deployment.

Contact US

Get in Touch

we provide best services. Need Help?