Upgradeable Greeter contract

mail@pastecode.io avatar
unknown
javascript
a year ago
1.1 kB
3
Indexable
Never
-----------------------
    SMART CONTRACT     
-----------------------

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "./OwnableUpgradeable.sol";

contract Greeter is OwnableUpgradeable {
    mapping(address=> string) public greetings;

    function __Greeter_init() public initializer {
        __Ownable_init(msg.sender);
    }

    function greet() public view returns (string memory) {
        return greetings[_msgSender()];
    }

    function setGreeting(string memory _greeting) public {
        greetings[_msgSender()] = _greeting;
    }
}



----------------------
  DEPLOYMENT SCRIPT
----------------------

import { ethers, upgrades } from "hardhat";

async function main() {
  const Greeter = await ethers.getContractFactory("Greeter");
  const greeter = await upgrades.deployProxy(
    Greeter, 
    [], 
    {
      initializer: "__Greeter_init",
    }
  );

  await greeter.deployed();

  console.log("Greeter deployed to:", greeter.address);
}

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