Solidity, the primary language for writing smart contracts on blockchain platforms like Celo, has a feature known as events that allow you to log certain actions within the contract. This challenge focuses on implementing a transaction log using Solidity events.
Create a contract for a simple token transfer with a transaction log. The requirements are as follows:
- The contract should maintain a ledger of token balances for each address.
- It should have a function to transfer tokens from one address to another.
- An event named “Transfer” should be emitted every time a token transfer occurs.
- The “Transfer” event should log the sender’s address, the recipient’s address, and the amount of tokens transferred.
- A function should be present to query the token balance of a specific address.
mappingin Solidity to create the ledger of token balances.
msg.senderglobal variable can be used to denote the sender in a transaction.
eventkeyword can be used to define the “Transfer” event.
emitkeyword is used to trigger an event.
- Remember to update the sender and recipient’s balance in the transfer function after emitting the event.
- Correctity: The contract should compile without errors and meet all requirements.
- Readability: The contract should be easy to understand, with comments explaining the code.
- Testability: You should also provide examples of how to test each function of the contract.
Please note, while this challenge focuses on event logging, it does not cover important aspects like security, gas optimization, or contract upgradability, which are crucial for real-world contract deployment on the Celo platform.
To deepen your understanding of Celo smart contracts and Solidity, consider reading through the Celo and Solidity tutorials.
Please reply with a link to your PR on GitHub - celo-academy/Solidity-Events-Implementing-a-Transaction-Log-Coding-Challenge, including your token transfer contract and transaction log. Also, include any notes or comments you think are necessary for understanding your design and choices. Lastly, provide a brief explanation about how each function of the contract should be tested.