Coding Journey: Personal log

ERC20 turns five

I only realized when recommending a community member read the EIP and noticed the date. I had to check the date of the original issue: https://github.com/ethereum/eips/issues/20

Always be closing

Whilst I am not a maintainer, this is great advice.

Copy paste

The forum has this awesome widget for copying a block of code (top right corner of code below).
I keep looking for it when I use the documentation: https://docs.openzeppelin.com/learn/developing-smart-contracts#first-contract

// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

Grateful

Linking a Library in Hardhat

Answer.sol

// contracts/Answer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

library Answer {
    function getAnswer() public returns (uint256) {
        return 42;
    }
}

Box.sol

// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
 
import "./Answer.sol";

contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);
 
    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    function storeAnswer() public {
        store(Answer.getAnswer());
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

Deploy.js

// scripts/deploy.js
async function main() {
    const Answer = await ethers.getContractFactory("Answer");
    console.log("Deploying Answer...");
    const answer = await Answer.deploy();
    await answer.deployed();
    console.log("Answer deployed to:", answer.address);

    // Library linking: https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#library-linking 
    const Box = await ethers.getContractFactory("Box", {libraries: { Answer: answer.address} });
    console.log("Deploying Box...");
    const box = await upgrades.deployProxy(Box, [42], { initializer: 'store', unsafeAllowLinkedLibraries: true });
    console.log("Box deployed to:", box.address);
  }
  
  main()
    .then(() => process.exit(0))
    .catch(error => {
      console.error(error);
      process.exit(1);
    });

Convert Markdown to asciidoc

OpenZeppelin Documentation is in asciidoc format.
When converting from Markdown (e.g. in the forum or from Notion) you can use pandoc.

pandoc --wrap=none --atx-headers -t asciidoc -f markdown --smart < test.md > test.adoc

GasNow

I deployed an NFT last week. https://www.gasnow.org/ is my favorite check for gas prices.