Last active
October 3, 2023 14:06
-
-
Save Violet-Bora-Lee/73f99f444cf0ec7cf6717ca55cacb28d to your computer and use it in GitHub Desktop.
솔리디티 상태변수 예시
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.0; | |
contract SimpleToken { | |
// state 변수로 각 주소의 잔액을 저장 | |
mapping(address => uint256) public balances; | |
// 초기 잔액 설정 | |
constructor(uint256 initialSupply) { | |
balances[msg.sender] = initialSupply; | |
} | |
// 토큰 전송 함수 | |
function transfer(address _to, uint256 _amount) public { | |
require(balances[msg.sender] >= _amount, "Insufficient balance"); | |
balances[msg.sender] -= _amount; | |
balances[_to] += _amount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment