Skip to content

Instantly share code, notes, and snippets.

@Violet-Bora-Lee
Last active October 3, 2023 14:06
Show Gist options
  • Save Violet-Bora-Lee/73f99f444cf0ec7cf6717ca55cacb28d to your computer and use it in GitHub Desktop.
Save Violet-Bora-Lee/73f99f444cf0ec7cf6717ca55cacb28d to your computer and use it in GitHub Desktop.
솔리디티 상태변수 예시
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