Smart Contract와 Solidity

2022. 8. 26. 10:18Block Chain

Smart Contract를 공부하면서 불새! 쫄불! - 블록체인 전문방송을 많이 참고하였습니다.

 

불새! 쫄불! - 블록체인 전문방송

도대체 토큰 이코노미는 뭔가요? 본격 블록체인 비즈니스 전문방송! "불새! 블록체인 세상" 블록체인 요정도는 알아야죠! 토큰 이코노미 뉴비를 위한 "쫄불! - 쫄지마! 블록체인" 벤처캐피탈 대표

www.youtube.com

Smart Contract란?

 

Smart contract - Wikipedia

From Wikipedia, the free encyclopedia Jump to navigation Jump to search Transaction on a decentralized platform A smart contract is a computer program or a transaction protocol that is intended to automatically execute, control or document legally relevant

en.wikipedia.org

A smart contract is a computer program or a transaction protocol that is intended to automatically execute, control or document legally relevant events and actions according to the terms of a contract or an agreement.

 

위키피디아에서 스마트 컨트랙트란 계약이나 합의에 의해 특정 사건이나 행동을 기록하고, 실행하고, 관리하는 컴퓨터 프로그램 혹은 트랜잭션 프로토콜이라고 소개하고 있습니다. 말이 그렇게 와닿지는 않네요.

 

Smart Contract란 Blockchain의 분산 원장 기술(Distributed Ledger Technology, DLT)이라는 특성을 이용해 중개자 없이 P2P로 다양한 형태의 계약을 체결하고 이행하는 것을 말한다. 이 기술은 이더리움 블록체인을 기반으로 해 비트코인보다 한 단계 발전했다고 해서 블록체인 2.0 이라고도 부른다.

 

제가 참고 했던 유투브의 블록체인 백과사전 4회를 보시면 나와 있는 설명입니다. 기존의 블록체인과 같은 경우 거래 장부로서의 역할이 주 역할이었다면, Smart Contract를 통해 거래 장부 뿐만 아니라 금융 거래, 부동산 계약, 공증 등 계약을 진행할 수 있게 발전하였습니다.

 

이런 Smart Contract의 개념은 1996년 닉 자보(Nick Szabo)가 처음 제안하였으며, 이 아이디어를 비탈릭 부테린(Vitalik Buterin)이 개발하였습니다. 기존의 비트코인의 소스 코드를 일부 수정하여 구현하고자 하였으나, 비트코인 커뮤니티에서 받아들여지지 않자 비트코인을 fork하여 새로 Ethereum을 만들었습니다.

이 기능을 사용하면, 개발자가 직접 계약 조건과 내용을 코딩할 수 있기 때문에, 원칙적으로 인간이 상상할 수 있는 모든 종류의 계약을 Ethereum 플랫폼을 이용해 구현할 수 있습니다.

 

그렇다면 어떻게 Smart Contract를 구현할 수 있을까요?

이를 위해선 Solidity라고 하는 프로그래밍 언어를 알아야합니다.

Solidity란?

 

Solidity — Solidity 0.8.16 documentation

1. Understand the Smart Contract Basics If you are new to the concept of smart contracts we recommend you to get started by digging into the “Introduction to Smart Contracts” section, which covers: 2. Get to Know Solidity Once you are accustomed to the

docs.soliditylang.org

Solidity is an object-oriented, high-level language for implementing smart contracts.
Solidity is most profoundly influenced by C++, but also borrowed concepts from languages like Python, JavaScript, and others.

 

Solidity의 공식 문서를 보면 Solidity는 Smart Contract를 구현하기 위한 객체 지향적이고, 고수준의 언어라고 소개합니다. 또한 Solidity는 C++에서 가장 많이 영향을 받았고, Python, JavaScript와 같은 언어들의 컨셉을 빌려왔다고 합니다.

따라서 기존의 프로그래밍을 해보신 분이라면 어렵지 않게 이해할 수 있을 것입니다.

contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    function name() public view virtual override returns (string memory) {
        return _name;
    }

    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }
}
 

GitHub - OpenZeppelin/openzeppelin-contracts: OpenZeppelin Contracts is a library for secure smart contract development.

OpenZeppelin Contracts is a library for secure smart contract development. - GitHub - OpenZeppelin/openzeppelin-contracts: OpenZeppelin Contracts is a library for secure smart contract development.

github.com

위 코드는 OpenZeppelin의 ERC20 코드의 일부를 발췌한 것입니다. 아직 Tistory의 코드 블럭에는 Solidity가 없어서 색깔이 이상하게 입혀졌네요.

 

한 번 읽어보시면 객체 지향 언어 답게 생성자(Constructor)가 있고, is 예약어를 통한 상속이 있고, 변수의 타입도 있습니다. Solidity를 처음 보시는 분들도 기존에 프로그래밍 경험이 있다면 쉽게 이해할 수 있을 것입니다. 이렇게 Solidity를 이용해 Smart Contract의 조건을 코딩하고 배포할 수 있습니다. 

 

오늘은 Smart Contract와 Solidity에 대해 대략적으로 알아봤습니다. 다음 포스팅 부터는 제가 예전에 작성했던 Remix IDE와 Solidity를 이용하여 실제로 코딩하고, 배포하는 방법을 알아보겠습니다.