Tags
- oracle
- web developer
- postman html parse
- LSL_Script
- postman
- 다빈치 리졸브
- postman pre-request
- 프런트엔드
- postman collection
- Android
- postman session
- postman automations
- Unity
- Android/iOS Developer
- postman csv
- postman collection variables
- emplace_back
- Front-end developer
- 좋은 개발자
- Interaction developer
- Intellij
- solidity
- MFC
- postman excel
- Java
- c#
- 우수한 프런트 개발자
- C++
- postman tests
- UI/UX Engineer
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Archives
- Today
- Total
david's daily developer note
[Solidity] 4.Mapping 본문
728x90
솔리디티에서 mapping 키워드를 통하여 정의하는 맵핑은, 키-값 (key-value) 쌍으로 표현되는 데이터 저장 방법이다. C++ STL의 map이나 set, C#의 dictionary 와 사용법과 개념이 비슷하다.
mapping (address => uint) public balance;
mapping (uint => string) idToName;
예시의 balance 맵핑은 특정 이더리움 주소(address)에 저장된 수량(uint)을 표현하였고, 키는 address이고 값은 uint이다. idToName 맵핑은 사용자 Id(unit)와 이름(string) 정보를 표현하며, 키는 uint이고 값은 string이다.
다음은 호출된 컨트랙트 함수에서 mapping을 업데이트하는 예이다.
mapping (address => uint256) private _balances;
function transfer(uint amount) public {
_balances[msg.sender] += amount;
}
_balances는 이더리움 주소의 잔액을 관리하는 맵핑이다. transfer 함수에 전달된 amount만큼 주소의 잔액을 증감한다.
여기서 msg.sender는 현재 함수를 호출한 주소를 나타낸다. 컨트랙트는 블록체인을 변경하지만, 외부 호출자가 실행하지 않는다면 아무일도 일어나지 않는다.
또한, 맵핑은 맵핑을 값으로 포함할 수 있다.
pragma solidity >=0.4.22 <0.9.0;
mapping (address => mapping (address => uint256)) private _allowances;
예시의 _allowances 맵핑의 키는 address이고, 값은 다시 맵핑 (address, uint256)이다.
728x90
'[Blockchain] > develop' 카테고리의 다른 글
[Solidity] 5.Error handling : Assert, Require, Revert (0) | 2022.08.16 |
---|---|
[Solidity] 3.Event (0) | 2022.08.14 |
[Solidity] 2.Function (0) | 2022.08.14 |
[Solidity] 1.Basics & Language description (0) | 2022.08.13 |