[BlockChain] Ethereum IDE - Remix

HYEOB KIM·2023년 2월 21일
0

BlockChain

목록 보기
2/3

Ethereum IDE - Remix

  • 스마트 계약을 실행할 수 있는 통합 개발 환경
  • 플러그인을 설치해서 Solidity를 작성할 수 있고 스마트 계약을 설정한 후 테스트 네트워크에 들어가볼 수도 있음.
  • 탈중앙화 토큰, DApp을 전반적으로 이해하고 DApp을 작성하는 기술을 배우는데 도움을 줌.

=> https://remix.ethereum.org/#optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.17+commit.8df45f5f.js

계약 컴파일 -> 스마트 계약 배포

단위 테스트(Unit Testing) : 스마트 계약 작성 시 아주 중요

스마트 계약

두 계약 당사자 간에 이뤄지는 합의
왜 스마트할까
제3자가 컴퓨터 프로그램으로 대체되기 때문
스마트 계약에 들어가는 코드는 양 당사자를 위한 것
모든 일은 양 당사자가 규정한 조건 안에서 발생
왜 유용할까
다양한 이유로 사용되는데 기존 블록체인 네트워크를 사용 가능하다는 점이 제일 큼.
예를 들어, 블록체인 기술을 사용하면 음악을 전송할 수 있음
네트워크에서 음악을 안전하게 전송하려면 두 가지 방법이 있음
내가 직접 블록체인을 구축하거나
이더리움 같은 기존의 블록체인 네트워크를 이용 -> 이때 스마트 계약을 통해 안전하게 전송
블록체인 소유자들은 애플리케이션에서 따라야 할 스마트 계약 가이드라인을 제공
Solidity로 스마트 계약을 구축
스마트 계약을 사용하면 자체 토큰도 만들어 이더리움에 peg(페그)할 수 있음.
이더리움 토큰을 사용할 필요 없음.

스마트 계약 기초

// PRAGMA : solidity를 불러온다. It indicats the solidity version that is being used. 첫 줄에 반드시 작성해야 함.
pragma solidity >=0.7.0 <0.9.0;

// create a contract that can store data and return the data back

// be able to do the following:

// 1. receive information, 2. store information, 3. return the information back

// A Contract in the sense of Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain.

/*
While writing program in any language, you need to use various variables to store various information.
Variables are nothing but reserved memory locations to store values.
This means that when you create a variable you reserve some space in memory
*/

// Variable: are used to store information to be referenced and manipulated in a code.

// In solidity when we declare variables we statically type them out

// A fuction is a group of reusable code that can be used anywhere in your application.

contract simpleStorage {
    // write all the code inside here - functions and its state

    uint storeData;

    // set and get

    // public enables visibility so that we can call this outside of the contract itself.
    function set(uint x) public {
        storeData = x;
    }

    // view는 함수의 상태가 수정되지 않도록 함.
    // returns (uint) : 정수를 반환하도록 해준다.
    function get() public view returns (uint) {
        return storeData;
    }

    // every we run set and get, transaction execute, stored in blockchain.
    // 트랜잭션이 실행될 때마다 가스비가 발생
}
pragma solidity >=0.7.0 <0.9.0;

// 1. create a storage contract that sets and gets values - only the value it returns is multipled 5x
contract simpleStorage {

    uint storeData;

    function set(uint x) public {
        storeData = x * 5;
    }

    function get() public view returns (uint) {
        return storeData;
    }
}
profile
Devops Engineer

0개의 댓글