상세 컨텐츠

본문 제목

Solidity - First Application

Programming Language/Solidity

by Yongari 2022. 12. 19. 21:43

본문

Here is a simple contract that you can get, increment and decrement the count store in this contract. 

이 계약에서 카운트 저장값을 가져오고, 증가하고, 감소시킬 수 있는 간단한 계약이 있습니다. 

 

다음 코드를 통해 살펴봅시다.

 

// SPDX-License-Identifier: MIT
// Solidity 버전 선언
pragma solidity ^0.8.13;

contract Counter {
    unsigned int면서 public한 변수로 count 선언
    uint public count;

    // Function to get the current count
    function get() public view returns (uint) {
        return count;
    }

    // Function to increment count by 1
    // 1씩 더해지는 count 변수 
    function inc() public {
        count += 1;
    }

    // Function to decrement count by 1
    // 1씩 마이너스 되는 count 변수 
    function dec() public {
        // This function will fail if count = 0
        count -= 1;
    }
}

'Programming Language > Solidity' 카테고리의 다른 글

Solidity - Immutable  (0) 2022.12.21
Solidity - Constants  (0) 2022.12.21
Solidity - Variables  (0) 2022.12.21
Solidity - Primitive Data Types  (0) 2022.12.19
Solidity - Hello World  (0) 2022.12.19

관련글 더보기