Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Adding Vietnamese #711

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions vi/1/00-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Xây Nhà máy Zombie
header: Xin chào, Con người!
roadmap: roadmap.jpg
path: solidity
publishedOn: Cryptozombies
---

<!-- So you think you have what it takes to become a **CryptoZombie**, huh? -->
Thế ngươi tự tin có đủ khả năng trở thành **CryptoZombie** à?

<!-- This course will teach you how to **build a game on Ethereum**. -->
Khóa học này sẽ dạy ngươi cách **xây dựng một trò chơi trên Ethereum**.

<!-- It's designed for beginners to Solidity, but it assumes you have some experience
programming in another language (e.g. JavaScript). -->
Khóa học này được thiết kế cho người mới bắt đầu với Solidity, nhưng mặc định ngươi đã có một chút kinh nghiệm
lập trình với ngôn ngữ khác (như JavaScript).
75 changes: 75 additions & 0 deletions vi/1/arrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: Arrays
actions: ['checkAnswer', 'hints']
material:
editor:
language: sol
startingCode: |
pragma solidity >=0.5.0 <0.6.0;

contract ZombieFactory {

uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;

struct Zombie {
string name;
uint dna;
}

// start here

}
answer: >
pragma solidity >=0.5.0 <0.6.0;


contract ZombieFactory {

uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;

struct Zombie {
string name;
uint dna;
}

Zombie[] public zombies;

}
---

When you want a collection of something, you can use an **_array_**. There are two types of arrays in Solidity: **_fixed_** arrays and **_dynamic_** arrays:

```
// Array with a fixed length of 2 elements:
uint[2] fixedArray;
// another fixed Array, can contain 5 strings:
string[5] stringArray;
// a dynamic Array - has no fixed size, can keep growing:
uint[] dynamicArray;
```

You can also create an array of **_structs_**. Using the previous chapter's `Person` struct:

```
Person[] people; // dynamic Array, we can keep adding to it
```

Remember that state variables are stored permanently in the blockchain? So creating a dynamic array of structs like this can be useful for storing structured data in your contract, kind of like a database.

## Public Arrays

You can declare an array as `public`, and Solidity will automatically create a **_getter_** method for it. The syntax looks like:

```
Person[] public people;
```

Other contracts would then be able to read from, but not write to, this array. So this is a useful pattern for storing public data in your contract.

# Put it to the test

We're going to want to store an army of zombies in our app. And we're going to want to show off all our zombies to other apps, so we'll want it to be public.

1. Create a public array of `Zombie` **_structs_**, and name it `zombies`.
94 changes: 94 additions & 0 deletions vi/1/arraysstructs2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: Working With Structs and Arrays
actions: ['checkAnswer', 'hints']
material:
editor:
language: sol
startingCode: |
pragma solidity >=0.5.0 <0.6.0;

contract ZombieFactory {

uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;

struct Zombie {
string name;
uint dna;
}

Zombie[] public zombies;

function createZombie (string memory _name, uint _dna) public {
// start here
}

}
answer: >
pragma solidity >=0.5.0 <0.6.0;


contract ZombieFactory {

uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;

struct Zombie {
string name;
uint dna;
}

Zombie[] public zombies;

function createZombie (string memory _name, uint _dna) public {
zombies.push(Zombie(_name, _dna));
}

}
---

### Creating New Structs

Remember our `Person` struct in the previous example?

```
struct Person {
uint age;
string name;
}

Person[] public people;
```

Now we're going to learn how to create new `Person`s and add them to our `people` array.

```
// create a New Person:
Person satoshi = Person(172, "Satoshi");

// Add that person to the Array:
people.push(satoshi);
```

We can also combine these together and do them in one line of code to keep things clean:

```
people.push(Person(16, "Vitalik"));
```

Note that `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]
```

# Put it to the test

Let's make our createZombie function do something!

1. Fill in the function body so it creates a new `Zombie`, and adds it to the `zombies` array. The `name` and `dna` for the new Zombie should come from the function arguments.
2. Let's do it in one line of code to keep things clean.
71 changes: 71 additions & 0 deletions vi/1/contracts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
# title: "Contracts"
title: "Hợp đồng"
actions: ['checkAnswer', 'hints']
material:
editor:
language: sol
startingCode: |
pragma solidity // 1. Điền phiên bản Solidity vào đây

// 2. Viết hợp đồng ở đây
answer: >
pragma solidity >=0.5.0 <0.6.0;


contract ZombieFactory {

}
---

<!-- Starting with the absolute basics: -->
Ta bắt đầu từ những bước cơ bản nhất:

<!-- Solidity's code is encapsulated in **contracts**. A `contract` is the fundamental building block of Ethereum applications — all variables and functions belong to a contract, and this will be the starting point of all your projects. -->
Mã Solidity được đóng gói trong các **hợp đồng**. `Hợp đồng` là viên gạch cơ bản nhất để xây ứng dụng Ethereum - tất cả các biến và hàm đều thuộc về một hợp đồng, và cũng chính hợp đồng sẽ là điểm khởi đầu cho tất cả các dự án của ngươi.

<!-- An empty contract named `HelloWorld` would look like this: -->
Một hợp đồng rỗng mang tên `HelloWorld` (`ChàoThếGiới` ) sẽ trông như thế này:

```
contract HelloWorld {

}
```

<!-- ## Version Pragma -->
## Chỉ thị Phiên bản (Version Pragma)

<!-- All solidity source code should start with a "version pragma" — a declaration of the version of the Solidity compiler this code should use. This is to prevent issues with future compiler versions potentially introducing changes that would break your code. -->
Tất cả mã nguồn Solidity nên bắt đầu với một "chỉ thị phiên bản" - một khai báo về phiên bản compiler Solidity tương thích với mã nguồn này. Đây là để ngăn chặn các lỗi có thể xảy ra với mã nguồn của ngươi do không tương thích với các phiên bản compiler mới hơn.

<!-- For the scope of this tutorial, we'll want to be able to compile our smart contracts with any compiler version in the range of 0.5.0 (inclusive) to 0.6.0 (exclusive).
It looks like this: `pragma solidity >=0.5.0 <0.6.0;`. -->
Trong khuôn khổ của khóa học này, ngươi sẽ muốn biên dịch (compile) các hợp đồng thông minh (smart contract) của ngươi với compiler trong khoảng phiên bản từ ít nhất 0.5.0 đến thấp hơn 0.6.0.

<!-- Putting it together, here is a bare-bones starting contract — the first thing you'll write every time you start a new project: -->
Sau khi tổng hợp lại, dưới đây là khung xương một hợp đồng đơn giản nhất - cũng là những dòng đầu tiên ngươi sẽ viết mỗi khi bắt đầu một dự án mới:

```
pragma solidity >=0.5.0 <0.6.0; // trình báo phiên bản compiler

// hợp đồng HelloWorld
contract HelloWorld {

}
```

<!-- # Put it to the test -->
# Thực hành xem!

<!-- To start creating our Zombie army, let's create a base contract called `ZombieFactory`. -->
Để bắt đầu xây dựng đội quân Zombie của ngươi, hãy tạo một hợp đồng gốc có tên `ZombieFactory`.

<!-- 1. In the box to the right, make it so our contract uses solidity version `>=0.5.0 <0.6.0`. -->
1. Trong hộp bên phải, hãy đảm bảo hợp đồng của ngươi sử dụng phiên bản solidity `>=0.5.0 <0.6.0`.

<!-- 2. Create an empty contract called `ZombieFactory`. -->
2. Tạo một hợp đồng rỗng có tên `ZombieFactory`.

<!-- When you're finished, click "check answer" below. If you get stuck, you can click "hint". -->
Khi ngươi hoàn tất, hãy nhấn "Kiểm tra đáp án" (check answer) bên dưới. Nếu ngươi bí, có thể nhấn "Gợi ý" (hint).
50 changes: 50 additions & 0 deletions vi/1/datatypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: State Variables & Integers
actions: ['checkAnswer', 'hints']
material:
editor:
language: sol
startingCode: |
pragma solidity >=0.5.0 <0.6.0;

contract ZombieFactory {

//start here

}
answer: >
pragma solidity >=0.5.0 <0.6.0;


contract ZombieFactory {

uint dnaDigits = 16;

}
---

Great job! Now that we've got a shell for our contract, let's learn about how Solidity deals with variables.

**_State variables_** are permanently stored in contract storage. This means they're written to the Ethereum blockchain. Think of them like writing to a DB.

##### Example:
```
contract Example {
// This will be stored permanently in the blockchain
uint myUnsignedInteger = 100;
}
```

In this example contract, we created a `uint` called `myUnsignedInteger` and set it equal to 100.

## Unsigned Integers: `uint`

The `uint` data type is an unsigned integer, meaning **its value must be non-negative**. There's also an `int` data type for signed integers.

> Note: In Solidity, `uint` is actually an alias for `uint256`, a 256-bit unsigned integer. You can declare uints with less bits — `uint8`, `uint16`, `uint32`, etc.. But in general you want to simply use `uint` except in specific cases, which we'll talk about in later lessons.

# Put it to the test

Our Zombie DNA is going to be determined by a 16-digit number.

Declare a `uint` named `dnaDigits`, and set it equal to `16`.
Loading