This article will introduce three highly practical Solidity tutorial websites: CryptoZombies, Chainshot, and Solidity by Example.
本文會介紹3個非常實用的Solidity tutorial websites,分別是CryptoZombies、Chainshot 和 Solidity by example。
CryptoZombies is an interactive online course for learning Solidity language and Ethereum smart contract development. The course has a Chinese version tailored for Solidity 0.4.19, while the English version teaches Solidity >=0.5.0 <0.6.0. Although the version is quite old, it still serves as an interesting and enjoyable learning platform. After completing CryptoZombies, you can continue learning syntax and further your understanding through Chainshot.
CryptoZombies 是一個學習 Solidity 語言和以太坊智能合約開發的互動式線上課程。該課程中文版是針對 Solidity 0.4.19版本,英文版solidity >=0.5.0 <0.6.0進行教學。雖然版本很舊了,但仍然不失為一個有趣好玩的學習平台。在玩CryptoZombies 之後,我們可以透過Chainshot繼續學習語法。
I have compiled the key points and comparisons from the first two lessons of the course:

In Solidity, functions are set to be public by default. This means that anyone, including other contracts, can call and execute the code of your contract's functions. However, it is generally considered good practice to make functions private by default to prevent potential vulnerabilities in your contract that could be exploited by attackers. You can then selectively make only the necessary functions public to expose them to the world.
Similar to function parameters, Solidity uses an underscore (_) at the beginning of the name of private functions to differentiate them from public functions.
function createZombie(string memory _name, uint _dna) public {
zombies.push(Zombie(_name, _dna));
}
function _createZombie(string _name, uint _dna) private{
zombies.push(Zombie(_name, _dna));
}
Structs allow you to create more complicated data types that have multiple properties.
Note that we just introduced a new type, string. Strings are used for arbitrary-length UTF-8 data. Ex. string greeting = "Hello world!"
Array. push() adds something to the end of the array, so the elements are in the order we added them. See the following example:
uint[] numbers;
numbers.push(5);
numbers.push(10);
numbers.push(15);
// numbers is now equal to [5, 10, 15]
In Solidity, the function declaration contains the type of the return value, e.g. string.
View functions are read-only functions that do not modify the state of the contract. They are useful when you want to read the current state of the contract without changing it. View functions are executed locally and do not require a transaction to be mined on the blockchain.
function sayHello() public view returns (string memory)
On the other hand, pure functions, do not read or modify the state of the contract. They are useful when you want to perform a calculation or transformation on some input parameters and return a result. Pure functions are also executed locally and do not require a transaction to be mined on the blockchain.
function _multiply(uint a, uint b) private pure returns (uint) {
return a * b;
}
The keccak256 hash function essentially takes an input and transforms it into a unique 256-bit hexadecimal number. Even a minor alteration in the input data can produce a vastly different hash value.
//6e91ec6b618bb462a4a6ee5aa2cb0e9cf30f7a052bb467b0ba58b8748c00d2e5
keccak256(abi.encodePacked("aaaab"));
//b1f078126895a1424524de5321b339ab00408010b7cf0e6ed451514981e58aa9
keccak256(abi.encodePacked("aaaac"));
Events in your contract can serve as a means of notifying your application's front-end that a specific action has taken place on the blockchain. This information can be detected by the front-end(JavaScript), which can then initiate appropriate responses.
// declare the event
event IntegersAdded(uint x, uint y, uint result);
function add(uint _x, uint _y) public returns (uint) {
uint result = _x + _y;
// fire an event to let the app know the function was called:
emit IntegersAdded(_x, _y, result);
return result;
}

Require makes it so that the function will throw an error and stop executing if some condition is not true
"Storage refers to variables that are permanently stored on the blockchain.
Sandwich storage mySandwich = sandwiches[_index];
// mySandwich` is a pointer to `sandwiches[_index]`
mySandwich.status = "Eaten!";
// ...this will permanently change `sandwiches[_index]` on the blockchain.
While memory variables are temporary and only exist between external function calls. This is like the difference between a computer's hard drive and its RAM.
// If you just want a copy, you can use `memory`:
Sandwich memory anotherSandwich = sandwiches[_index + 1];
// `anotherSandwich` will simply be a copy of the
// data in memory, and...
anotherSandwich.status = "Eaten!";
// ...will just modify the temporary variable and have no effect on `sandwiches[_index + 1]`. But you can do this:
sandwiches[_index + 1] = anotherSandwich;
Most of the time, it's not necessary to explicitly use these keywords because Solidity handles them automatically. Variables declared outside of functions are stored in storage and written permanently to the blockchain by default, while variables declared within functions are stored in memory and are erased when the function call ends.
In Solidity, the visibility specifiers internal and external modify the accessibility of functions and state variables within a contract.
The internal specifier is the same as private, but with the additional feature that it can also be accessed by any contracts that inherit from the current contract. This can be useful when you want to expose certain functions or state variables to derived contracts, while keeping them hidden from the outside world.
On the other hand, the external specifier is similar to public, except that the functions marked as external can only be called from outside the contract. They cannot be invoked by other functions within the same contract. This can be helpful in situations where you want to limit access to certain functions to external actors only, such as other contracts or external user interfaces. `
contract Sandwich {
uint private sandwichesEaten = 0;
function eat() internal {
sandwichesEaten++;
}
}
contract BLT is Sandwich {
uint private baconSandwichesEaten = 0;
function eatWithBacon() public returns (string memory) {
baconSandwichesEaten++;
// We can call this here because it's internal
eat();
}
}
A mapping is a data structure that functions as a repository for data, organized as key-value pairs and utilized for both storage and retrieval purposes
In the example, we will utilize two mappings to maintain records of zombie ownership: one for tracking the address of the zombie's owner, and another for keeping count of the number of zombies owned by each owne.
mapping (uint => address) public zombieToOwner;
mapping (address => uint) ownerZombieCount;
Solidity provides access to a set of global variables that are universally accessible to all functions. One such variable is msg.sender, which corresponds to the address of the entity (be it a person or smart contract) that initiated the current function call. By leveraging msg.sender, one can ensure the security of their data on the Ethereum blockchain, as any attempts to modify another user's data would require access to the private key linked to their Ethereum address.
An example of using msg.sender and updating a mapping:
mapping (address => uint) favoriteNumber;
function setMyNumber(uint _myNumber) public {
// Update our `favoriteNumber` mapping to store `_myNumber` under `msg.sender`
favoriteNumber[msg.sender] = _myNumber;
// ^ The syntax for storing data in a mapping is just like with arrays
}

Chainshot 是一個線上學習平台,提供了針對 Solidity 的課程和教學資源,從基礎知識到高級主題都有涵蓋,包括理論知識、實際編程練習和項目案例,這些可以在線上編寫、測試和部署 Solidity 智能合約,是一個無論是初學者還是有經驗的開發人員都適合的學習平台。 除了 Solidity 課程外,Chainshot 還提供其他區塊鏈相關的課程,包括以太坊開發工具、智能合約安全性、去中心化金融等主題。這些課程的目標是幫助學習者建立實用的區塊鏈開發技能,並應用於真實世界的項目中。
Chainshot is an online learning platform that offers courses and educational resources for Solidity. It covers a wide range of topics, from basic knowledge to advanced subjects, including theoretical concepts, practical coding exercises, and project examples. Through Chainshot, you can write, test, and deploy Solidity smart contracts in an interactive online environment. It caters to both beginners and experienced developers, providing a platform suitable for anyone interested in learning Solidity.
In addition to Solidity courses, Chainshot also offers other blockchain-related courses, such as Ethereum development tools, smart contract security, decentralized finance, and more. The goal of these courses is to help learners build practical blockchain development skills and apply them to real-world projects.
Solidity by Example is a website that provides a collection of Solidity code examples and explanations. It covers various Solidity concepts and features, showcasing practical code snippets that demonstrate how to implement different functionalities in smart contracts. This resource is particularly useful for developers who prefer learning through code examples and want to explore different use cases.
Solidity by Example 是一個提供 Solidity 代碼示例和解釋的網站。它涵蓋了各種 Solidity 概念和功能,展示了如何在智能合約中實現不同的功能性。這個資源對於喜歡通過代碼示例學習並想探索不同用例的開發者尤其有用。

These three tutorial websites offer valuable resources and hands-on learning opportunities for mastering Solidity. Whether you prefer gamified lessons, interactive coding exercises, or code examples, these platforms will help you gain a solid understanding of Solidity programming and smart contract development.
這三個教學網站提供了寶貴的資源和實踐學習機會,幫助您掌握 Solidity 編程和智能合約開發。無論您偏好遊戲化的課程、互動式編程練習還是代碼示例,這些平台都能幫助您深入了解 Solidity 和智能合約開發。
