All field notes

Productivity · Retrospective

A token in one session: the toolchain I demonstrated for Developer Kaki

A blue coin standing beside a stack of ten thin slabs topped with a small hard hat.
Concept illustration · AI-generated

June began with an ending. On the first of the month I pushed a final update of chain state for Trivechain's legacy chain and marked the trivechain-core repository as deprecated. Its README now says that TRVC is a token on Binance Smart Chain. After working on a chain's own client, the next thing I did was show other developers how little code a token on an existing chain needs.

The session

In early June I gave the third sharing session for the Developer Kaki Facebook group, a Facebook Live called "Introduction to Blockchain Ecosystem 2021 for Developers". The recording went up on my YouTube channel on 7 June and runs just over two hours. Part of the session was practical: create a token contract, test it and share the code.

The token is called Developer Kaki, symbol DEVK. It exists to teach, so I kept everything about it as plain as I could.

Ten lines of Solidity

The contract, DEVKToken, imports OpenZeppelin's ERC20 implementation and does one thing in its constructor: it names the token, sets the symbol and mints 10,000 tokens to the address that deploys it. There is no mint function after that, no owner and no pause. Everything a wallet calls, from balances to transfers and allowances, comes from the library.

That was the first lesson I wanted people to take from the session. The fastest code to write is code you do not write. The README I wrote for the repository describes OpenZeppelin as providing "battle tested" code, and that is the reason to use it in a demonstration. A developer who writes their own transfer logic in a live session spends the session debugging arithmetic instead of learning how a token reaches a chain.

The toolchain

I used four pieces, each with one job:

  • Hardhat to compile, run tests and run scripts, with the Solidity 0.8.0 compiler. Since 0.8.0, arithmetic overflow reverts by default, which removes a class of bugs without an extra library.
  • OpenZeppelin Contracts 4.1 for the token logic.
  • ethers.js with Waffle's chai matchers for the test.
  • Hardhat's Etherscan plugin, pointed at BscScan, to publish verified source.

The configuration lists three networks: Hardhat's in-process network for tests, the BSC testnet (chain ID 97) and BSC mainnet (chain ID 56). Moving between them is a command-line flag, so the same script serves as rehearsal and as the real thing.

One test, one script

The test deploys the contract on the local network and checks three values: the name, the symbol and the total supply. The supply it expects is the digits 10000 followed by eighteen zeros. The token has 18 decimals and the contract stores whole units of the smallest denomination, so a wallet that shows 10,000 DEVK is reading 10²² units from the chain. I like this test for teaching because it makes decimals visible.

The deploy script prints the deployer's address, deploys the contract, waits for the deployment to be mined and then asks BscScan to verify the source. Verification belongs in the script rather than on a checklist for later. An unverified token contract asks every holder to trust bytecode they cannot read.

Why a small, fixed supply

A teaching token should be boring. Ten thousand is a round number that keeps the decimal arithmetic easy to follow. Minting all of it in the constructor means the supply is settled the moment the contract exists.

The first question anyone should ask of a new token is who can create more of it. For DEVK the answer sits in the constructor and nowhere else. I would rather people learn to look for that answer on a contract with nothing to hide than on one where the answer is buried.

Sharing it afterwards

After the session I published the code under TriveAcademy's GitHub organisation, with a README that links the recording, and added an MIT licence. The configuration in the repository leaves the mnemonic and the BscScan API key as empty strings. Anyone who clones it supplies their own.

That detail is worth showing in a public session. A repository that teaches deployment should not be able to deploy anything by itself, and a secret that never enters version control cannot leak from it.

What made it fit

Looking at the month as a whole, the productive choices were the ones that removed work. An audited library replaced the token logic. One configuration file covered three networks. One test pinned down the three facts that matter. One script deployed and verified. What was left for the session was the part worth explaining: what a token is on a chain like BSC, and which questions to ask of one before trusting it.