Código reproduzido do tutorial abaixo qualificado com objetivo didático.
Tanto a linguagem solidity quanto as APIs passaram por atualizações de 2019 para 2024, de forma que o exemplo reproduzido contém as modificações necessárias para funcionar após tais atualizações.
https://www.dappuniversity.com/articles/the-ultimate-ethereum-dapp-tutorial