솔리디티 언어 개발도구(리믹스)
웹 브라우저 기반의 IDE인 리믹스를 살펴보겠다.
Remix - Ethereum IDE
remix.ethereum.org
파일탐색기
Create new file을 클릭하여 test.sol을 생성하여 아래의 내용을 입력하자
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
contract Test {
string public text;
constructor(string memory _text){
text = _text;
}
function setText(string memory _text) public {
text = _text;
}
function say() public view returns(string memory) {
return text;
}
function errorOccur(uint a) public pure returns(uint) {
require(a == 0, "hello wolre error.");
return a;
}
}
컴파일러
컴파일을 위해 Solidity compliler 탭으로 이동해 compliler와 solidity의 버전을 맞추어 Complie test.sol 클릭하면 된다.
아래쪽의 ABI(Application Binary Interface)는 작성한 코드의 인터페이스 정보가 저수준의 객체 형태로 정의된 것을 의미한다. Bytecode는 Java에서와 비슷하게 컴퓨터가 이해할 수 있는 언어로 변환한 형태이다.
ABI의 기본형태는 다음과 같다
{
type: "function" | "event",
inputs: [parameter type],
name: function's name | event's name,
outputs: [return type]
}
지금 작성한 코드는 이러한 형태로 보여진다.
[
{
"inputs": [
{
"internalType": "string",
"name": "_text",
"type": "string"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "a",
"type": "uint256"
}
],
"name": "errorOccur",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "say",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_text",
"type": "string"
}
],
"name": "setText",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "text",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
]
배포 및 테스트
4가지 항목을 살펴보겠다.
- ENVIRONMENT : 배포환경
- ACCOUNT : 배포할 주소(EOA) 선택
- CONTRACT : 배포할 스마트 컨트랙트 선택과 배포 버튼
- Deployed Contracts : 스마트 컨트랙트 테스트
Dev - Ganache Provider와 연결하여 가나슈 CLI로 만든 테스트 네트워크로 구축한 노드에 연결한다.
Ganache JSON-RPC Endpoint에는 가나슈 CLI로 생성한 IP주소와 포트를 입력후 OK를 눌러 해당 노드와 연결한다.
cmd에 명령어를 입력하여 마지막 부분 Listening on ~ 을 확인하자.
ganache-cli
ACCOUNT에서 배포할 EOA를 선택 후 CONTRACT에서 스마트 콘트랙트를 작성한 .sol 파일을 선택 후 Deploy를 클릭한다.
Deployed Contracts 쪽에서 패보된 콘트랙트를 확인할 수 있다.
또한 가나슈 CLI를 확인하면 배포 시 아래쪽 처럼 블록넘버, 블록이 만들어진 시간, 가스(수수료) 등이 표기된다.