스마트 컨트랙트

스마트 컨트랙트 배포/실행/조회를 할 수 있습니다. 배포와 실행은 트랙잭션을 만들기 때문에 계정에 충분한 aergo 토큰이 있어야만 합니다.

컴파일

스마트 컨트랙트 배포를 하기 위해서는 우선 컴파일을 해야 합니다. 컴파일을 위해서는 Compile 버튼을 클릭하거나 F7버튼을 클릭하면 됩니다.

../_images/compile-contract-before.png ../_images/compile-contract-after.png

배포

스마트 컨트랙트 컴파일을 한 후 배포를 할 수 있습니다.

인자 없이

생성자 인자 없이 배포할 수 있습니다.

-- no arguments
function constructor()
  system.setItem("k1", "v1")
end

...
../_images/deploy-without-args.png

인자 사용

생성자 인자와 함께 배포할 수 있습니다.

-- arguments (key, value)
function constructor(key, value)
  system.setItem(key, value)
end

...
../_images/deploy-with-args.png

Gas limit 설정한 후

Gas limit을 설정한 후 배포할 수 있습니다. 0인 경우 필요한 만큼 쓰겠다는 의미입니다.

../_images/deploy-with-gas-limit.png

Token과 함께

배포할 때 aergo token을 전송할 수 있습니다. 이 때 constructor 함수가 payable에 등록되어 있어야 합니다.

function constructor()
  system.setItem("k1", "v1")
end

...

-- registered as payable
abi.payable(constructor)
../_images/deploy-with-amount.png

추가 & 삭제

추가

이미 배포되어 있는 컨트랙트를 추가할 수 있습니다.

Contract 주소를 입력한 후 Import 버튼을 클릭

../_images/import-contract-enter.png

컨트랙트 삭제

../_images/import-contract-result.png

삭제

Contract를 IDE에서 삭제할 수 있습니다.

Trash 버튼을 클릭

../_images/remove-contract-before.png

컨트랙트 삭제

../_images/remove-contract-after.png

실행

컨트랙트 실행을 통해 state db의 상태를 바꿀 수 있습니다. 함수 실행을 위해서는 register로 등록되어 있어야 합니다.

인자 없이

인자없이 컨트랙트를 실행할 수 있습니다

...

-- no arguments
function setDefault()
  system.setItem("k1", "v1")
end

...

-- register as execution
abi.register(setDefault)
../_images/execute-without-args.png

인자 사용

인자를 가지고 컨트랙트를 실행할 수 있습니다

...

-- arguments (key, value)
function set(key, value)
  system.setItem(key, value)
end

...

-- register as execution
abi.register(set)
../_images/execute-with-args.png

Gas limit 설정한 후

Gas limit을 설정한 후 실행할 수 있습니다. 0인 경우 필요한 만큼 쓰겠다는 의미입니다.

../_images/execute-with-gas-limit.png

Token과 함께

Aergo 토큰과 함께 컨트랙트를 실행할 수 있습니다. 이를 위해서는 함수가 payable에 등록되어 있어야 합니다.

...

function run()
end

...

-- registered as payable
abi.payable(run)
../_images/execute-with-amount.png

수수료 전가

실행할 때 수수료를 컨트랙트 주소가 부담하게 할 수 있습니다. 이를 위해서는 함수가 fee_delegation로 등록되어 있어야 하며 컨트랙트에 aergo 토큰이 있어야 합니다.

...

function run()
end

-- registered as fee delegation
abi.fee_delegation(run)

-- register as execution
abi.register(run)
../_images/execute-with-fee-delegation.png

조회

컨트랙트 조회를 통해 내부 state db의 상태를 조회할 수 있습니다

인자 없이

함수 인자 없이 조회할 수 있습니다.

...

-- no arguments
function getDefault()
  return system.getItem("k1")
end

-- registered as register_view
abi.register_view(getDefault)
../_images/query-without-args.png ../_images/query-result.png

인자 사용

함수 인자를 사용하여 조회할 수 있습니다.

...

-- arguments (key)
function get(key)
  return system.getItem(key)
end

-- registered as register_view
abi.register_view(get)
../_images/query-with-args.png ../_images/query-result.png

가변인자

Lua에서는 가변인자를 지원합니다. 가변인자는 ... 로 표현됩니다.

...

-- ... : varargs
function set(key, ...)
  local s = ""
  for i,v in ipairs{...} do
    s = s .. v
  end
  system.setItem(key, s)
end

...

abi.register(set)

추가

+ 버튼을 클릭

../_images/varargs-add-before.png

인자 추가 완료

../_images/varargs-add-after.png

삭제

- 버튼을 클릭

../_images/varargs-remove-before.png

인자 삭제 완료

../_images/varargs-remove-after.png

재배포 (private 모드에서만 허용)

이미 배포된 컨트랙트에 재배포 할 수 있습니다. 재배포는 private 모드에서만 가능합니다. 재배포를 하는 계정은 이미 배포된 컨트랙트를 배포한 계정이어야 합니다.

컨트랙트 재배포를 위해서는 이미 배포되어 있는 컨트랙트 주소를 선택한 후 deploy 버튼을 클릭하면 됩니다.

../_images/redeploy-contract-selected.png