본문으로 건너뛰기
버전: 3.5.0

IRC20 토큰 생성

IRC20

IRC20은 IOST 블록체인에서 토큰을 구현하기 위한 표준입니다. 단순 송금 외에도 토큰 동결, 토큰 소각 등 유용한 기능들을 포함하며 세부 설정이 가능합니다.

token.iost는 IRC20의 구현체로, 모든 IRC20 토큰은 token.iost를 통해 생성되어야 합니다. iost 자체도 내장 시스템 컨트랙트인 token.iost를 기반으로 IRC20 표준에 맞춰 구현되어 있습니다.

토큰을 더 세부적으로 커스터마이즈하고 싶다면 커스텀 토큰 생성 문서를 참고하세요.

token.iost의 인터페이스는 다음과 같습니다.

// 토큰 생성
create(tokenSymbol, issuer, totalSupply, configJson); // string, string, number, json
issue(tokenSymbol, to, amountStr); // string, string, string
transfer(tokenSymbol, from, to, amountStr, memo); // string, string, string, string, string
transferFreeze(tokenSymbol, from, to, amountStr, unfreezeTime, memo); // string, string, string, string, number, string
destroy(tokenSymbol, from, amountStr); // string, string, string
// 조회 인터페이스
balanceOf(tokenSymbol, from); // string, string
supply(tokenSymbol); // string
totalSupply(tokenSymbol); // string

create(tokenSymbol, issuer, totalSupply, configJson)

필요 권한: issuer

TokenSymbol은 특정 토큰의 고유 식별자입니다. 즉, token.iost 컨트랙트에서 이미 사용된 tokenSymbol로 새 토큰을 만들 수는 없습니다. 길이는 2~16자이며, 문자 a-z, 0-9, _만 사용할 수 있습니다.

Issuer는 토큰 발행자로, issuer만이 임의의 계정에게 토큰을 발행할 권한을 가집니다. 일반적으로 토큰의 issuer는 계정이지만, 컨트랙트일 수도 있습니다. issuer가 컨트랙트 ID라면, 해당 컨트랙트만이 issue 메서드를 호출하여 토큰을 발행할 수 있습니다. 예를 들어 토큰 mytoken의 issuer가 컨트랙트 Contractabc라면, Contractabcissue를 호출하여 mytoken을 발행할 수 있습니다. 또한 ContractabcContractdef의 함수를 호출하면, Contractdef 역시 mytoken을 발행할 권한을 갖게 됩니다. 즉, 컨트랙트의 권한은 자신이 호출한 컨트랙트로 전달될 수 있습니다. 다른 컨트랙트를 호출하여 권한을 전달하려면 blockchain.call 대신 시스템 함수 blockchain.callWithAuthority를 사용해야 합니다.

TotalSupply는 int64 정수이며, issuer는 totalSupply를 초과하여 토큰을 발행할 수 없습니다.

ConfigJson은 토큰의 설정을 담는 JSON입니다. 지원되는 모든 설정 속성은 다음과 같습니다.

{
"decimal": 0~19 사이의 정수,
"canTransfer": true/false, false면 토큰을 전송할 수 없음,
"fullName": 토큰의 전체 이름을 나타내는 문자열
}

issue(tokenSymbol, acc, amountStr)

필요 권한: tokenSymbol의 issuer

acc 계정에 tokenSymbol을 발행합니다. amountStr은 발행할 수량을 나타내는 문자열로, "100", "100.999"와 같이 양의 고정소수점 표현이어야 합니다.

transfer(tokenSymbol, accFrom, accTo, amountStr, memo)

필요 권한: accFrom

tokenSymbol을 accFrom에서 accTo로 amountStr 만큼 메모와 함께 전송합니다. amount는 양의 고정소수점 표현이어야 하며, memo는 이번 송금에 대한 부가 문자열 메시지로 길이가 512 바이트를 넘지 않아야 합니다.

transferFreeze(tokenSymbol, accFrom, accTo, amountStr, unfreezeTime, memo)

필요 권한: accFrom

tokenSymbol을 accFrom에서 accTo로 amountStr 만큼 메모와 함께 전송하되, unfreezeTime까지 이 분량의 토큰을 동결합니다. unfreezeTime은 토큰 동결 해제 시점의 unix 시간을 나노초 단위로 표현한 값입니다.

destroy(tokenSymbol, accFrom, amountStr)

필요 권한: accFrom

accFrom 계정의 토큰을 amountStr 만큼 소각합니다. 소각 이후에는 토큰의 supply도 같은 만큼 줄어듭니다. 즉, 일부 토큰을 소각하면 totalSupply 범위 내에서 추가로 발행이 가능해집니다.

balanceOf(tokenSymbol, acc)

필요 권한: 없음

특정 토큰의 계정 잔액을 조회합니다.

supply(tokenSymbol)

필요 권한: 없음

특정 토큰의 현재 공급량을 조회합니다.

totalSupply(tokenSymbol)

필요 권한: 없음

특정 토큰의 totalSupply를 조회합니다.

단계별 예제

IOST 블록체인에서 IRC20을 만드는 일은 매우 간단합니다. token.iost 컨트랙트를 호출하기만 하면 됩니다.

아래는 bank 계정을 사용해 토큰을 만들고 계정 사이에 송금하는 단계별 예제입니다. 미리 bank, user0, user1 계정을 생성해 두어야 합니다.

iwallet call token.iost create '["mytoken", "bank", 21000000000, {"decimal": 8, "fullName": "token for test"}]' --account bank
iwallet call token.iost issue '["mytoken", "bank", "1000"]' --account bank
iwallet call token.iost issue '["mytoken", "user0", "100.00000001"]' --account bank
iwallet call token.iost transfer '["mytoken", "user0", "user1", "10", "user0 pay coffee"]' --account user0
iwallet call token.iost transferFreeze '["mytoken", "user1", "user0", "0.1", 1544880864601648640, "voucher"]' --account user1
iwallet call token.iost destroy '["mytoken", "bank", "1000"]' --account bank