05.08

조하빈 ·2023년 5월 8일
0
post-thumbnail

05월 08일 월요일


Solidity - 복습

contract note{
    struct Student {
        string name;
        uint birthday;
        uint number;
    }
    Student[] students;
    function pushStudent(string memory  _name, uint _birthday, uint _number) public {
        students.push(Student(_name, _birthday, _number));
    }
    // student 의 정보를 얻고싶을 때 
    function getStudent(uint _n ) public view returns(Student memory) {
        return students[_n-1];
    }
    // 생일의 정보만 얻고싶을 때
    function getBirthday(uint _n) public view returns(uint){
        return students[_n-1].birthday;
    }}

Solidity -


// address 는 20byte!! (정적)
// 0x000...(40자리)


Solidity - Mapping

contract Mapping{
mapping(uint => uint) a; // key-value 쌍이 숫자-숫자로 연결되어있는 maaping a
mapping(uint => string) b;
mapping(string => address) c;

// 이름을 검색하면 그 아이의 키를 반환받는 contract를 구현하고 싶다.
mapping(string => uint) height;

// 정보 넣기
function setHeight(string memory _name, uint _h )public {
    height[_name] = _h; // mapping이름 [key값] = value 값
}

// 정보 받기
function getHeight(string memory _name) public view returns(uint) {
    return height[_name];
}

}

profile
PPisland

0개의 댓글