-
Notifications
You must be signed in to change notification settings - Fork 0
/
Crud.sol
40 lines (31 loc) · 882 Bytes
/
Crud.sol
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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
contract sol{
struct User {
string name;
uint id;
}
User[] public user;
//recieve paramenter for the user name
//increment id from the length of the array
function create(string memory name) public{
user.push(User(name, user.length +1));
}
function read(uint uid) public view returns(string memory userName){
for(uint i = 0; i < user.length; i++){
if(user[i].id == uid){
userName = user[uid].name;
}
}
}
function update (uint id, string memory userName) public{
user[id].name = userName;
}
function remove(uint uid) public{
for(uint i = 0; i < user.length; i++){
if(user[i].id == uid){
delete user[i];
}
}
}
}