-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic.sol
More file actions
66 lines (53 loc) · 1.94 KB
/
Basic.sol
File metadata and controls
66 lines (53 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Solidity desde 0.
// https://remix-project.org/
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.7.0 < 0.9.0;
contract Employess{
// Por defecto las variables tienen visibilidad: internal
// value
uint256 public age; // se la seteo en publica
string name;
bool admin;
int256 favoriteNumber;
address wallet;
bytes32 txHash; // 64 caracteres
// reference
uint256[] numbers;
mapping(address => uint256) balances; // {'0x1234123214312312321321321ads': 123123}
mapping(uint256 => address) idToWallet; // {0: '0x12354g312312312321321f'}
// Como string es dinamico, hay que aclarar donde se lo guarda, dependiendo el lugar
// va a costar un fee distinto: "memory" or "calldata"
// Funciones
// Visibilidades posibles: public, internal
function setEmployee(uint256 _age, string memory _name, bool _admin, int256 _number, address _wallet) public {
age = _age;
name = _name;
admin = _admin;
favoriteNumber = _number;
wallet = _wallet;
}
}
contract Employess2{
struct Person {
uint256 age;
string name;
bool admin;
address wallet;
}
// array de 10 personas
// Person[10] myEmployess;
// Usando mappings es mejor, no hay que setear la cantidad
mapping(uint256 => Person) myEmployess;
function setEmployee(uint256 _index,uint256 _age, string memory _name, bool _admin, address _wallet) public {
myEmployess[_index].age = _age;
myEmployess[_index].age = _age;
myEmployess[_index].name = _name;
myEmployess[_index].admin = _admin;
myEmployess[_index].wallet = _wallet;
}
// se debe aclarar el tipo de retorno
// hay que aclarar si la función muta los datos, view significa que es solo lectura --> no se mutan
function getEmployee(uint256 _index) public view returns (Person memory){
return myEmployess[_index]; //devuelve una tupla
}
}