Coding Journey: Personal log

Starting out

One of my friends is starting out in the space.

I recommended that they subscribe to Week in Ethereum News.
Read Crypto Trends.

Watch Webinar Series: Introduction to Backrunning.

Sign up for: EthOnline.

They should also play Ethernaut.
Read Audits: https://blog.openzeppelin.com/security-audits/

If they haven’t already, create a GitHub account (version control) and a Twitter account (for Crypto Twitter). Ideally with the same username and profile pic. My preference is that the username is based on your name and that the profile pic shows your face (even if it is stylized). I use @abcoathup everywhere (github.com/abcoathup, twitter.com/abcoathup and of course the forum.)

Anything else you would recommend?

1 Like

Emoji

I :heart: using Emoji in social media posts.

I search for the best Emoji to use with emojipedia:

Job hunting

A friend is wanting to get into the space. I sent them the following wiki post I wrote:

PS OpenZeppelin are hiring: https://openzeppelin.com/jobs/

Internet

Pretty much everything I do in my role requires the internet.

Currently our 5G internet is down whilst they work on the mobile tower. Our mobile phones are with the same company, so we can’t use those either.

Normally I would go to a library or a cafe but Covid lockdown means they are all closed.

Instead I am using an old phone with a long life data sim on a separate (premium) network to keep the lights on.

Verification

I am really keen on multi-file verification. Flattening strips imports, strips license identifiers and is overall harder to read, identify and reproduce.

I have been using Builder Etherscan plugin but ran into the following issue:

For verification, until this is fixed I need to clean out any contracts and artifacts that I don’t want included in the verification.

1 Like

Verification

Multi-file verification is coming to Truffle

1 Like

Healthy Workstyle

:yin_yang: One of the core values of OpenZeppelin is Healthy Workstyle:

We are conscious of our individual work styles and achieve our goals calmly, while enjoying the journey.

I just had a few days vacation :desert_island: and am very grateful for that.
(Melbourne is still in lockdown. Whilst we can only go out for 2 hours exercise a day within 5km of home, I still managed to swim in the sea a couple of times).

:pray: Thanks to @martriay for supporting the community whilst I was away.


P.S. OpenZeppelin are hiring:

1 Like

asciinema

Sometimes a text based tutorial isn’t enough. This is where asciinema can step in.

https://asciinema.org/a/364291

Nicks method

How to deploy a contract with the same address on any chain (not using CREATE2)

Deployment Method

This contract is going to be deployed using the keyless deployment method—also known as Nick’s method—which relies on a single-use address. (See Nick’s article for more details). This method works as follows:

  1. Generate a transaction which deploys the contract from a new random account.
  • This transaction MUST NOT use EIP-155 in order to work on any chain.
  • This transaction MUST have a relatively high gas price to be deployed on any chain. In this case, it is going to be 100 Gwei.
  1. Set the v , r , s of the transaction signature to the following values:
v: 27,
r: 0x1820182018201820182018201820182018201820182018201820182018201820'
s: 0x1820182018201820182018201820182018201820182018201820182018201820'

Those r and s values—made of a repeating pattern of 1820 ’s—are predictable “random numbers” generated deterministically by a human.
3. We recover the sender of this transaction, i.e., the single-use deployment account.
Thus we obtain an account that can broadcast that transaction, but we also have the warranty that nobody knows the private key of that account.

  1. Send exactly 0.08 ether to this single-use deployment account.
  2. Broadcast the deployment transaction.

This operation can be done on any chain, guaranteeing that the contract address is always the same and nobody can use that address with a different contract.

Event naming

Events should be emitted immediately after the state change that they represent, and consequently they should be named in past tense.

From: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/GUIDELINES.md#solidity-code

Finding an email address

Including mine fortunately/unfortunately

Truffle Migrations don’t deploy new contract in testing

Setting overwrite: false when calling deploy in our migrations scripts means that we don’t deploy a new contract when testing.
See Truffle documentation for details: https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations#deployer-deploy-contract-args-options-

Discovered this in: Truffle Tests not being run against contract deployed to Ganache instead uses another contract address

Verification is still hard

To get the ABI encoded constructor/initialize we can use the following:

Hat tip @jeffthebaker


I struggled to verify a proxy, it was due to having OpenZeppelin Contracts 3.1 as a dependency rather than OpenZeppelin Contracts 3.2: Error verifying proxy with plugin @nomiclabs/hardhat-etherscan


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.