Contract

You can deploy/execute/query smart contract. Deploying and executing is done by making transaction. Make sure that you have enough aergo token to make transaction before deploying and executing contract.

Compile

Before deploying contract, you have to compile by clicking compile button or pressing F7.

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

Deploy

After compiling contract, you can deploy contract.

Without args

You can deploy contract without constructor arguments.

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

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

With args

You can deploy contract with constructor arguments.

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

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

Gas limit

You can deploy contract with gas limit configuration. 0 limit means infinite (uses as much as possible).

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

Amount

You can deploy contract with aergo token. Make sure constructor is registered as payable.

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

...

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

Import & Remove

Import

You can import already deployed contract.

Type contract address & click import button

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

Contract imported

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

Remove

You can remove contract.

Click trash button

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

Contract removed

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

Execute

Contract execution can change status of contract state db. Any function registered as register can be executed.

Without args

You can execute contract without arguments.

...

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

...

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

With args

You can execute contract with arguments.

...

-- 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

You can execute contract with configuring gas limit. 0 limit means infinite (uses as much as possible).

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

Amount

You can execute contract with aergo token. Make sure function is registered as payable.

...

function run()
end

...

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

Fee delegation

You can execute contract with fee delegation. When contract is executed with fee delegation, the contract pays fee on behalf of contract executor. Make sure function is registered as fee_delegation and a contract has enough aergo token.

...

function run()
end

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

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

Query

Contract query can check status of contract state db. Any function registered in register_view can be invoked as query.

Without args

You can query contract status without arguments.

...

-- 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

With args

You can query contract status with arguments.

...

-- 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

Varargs

Lua supports varargs. The varargs is denoted by … in argument.

...

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

...

abi.register(set)

Add

Click + button

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

Argument added

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

Remove

Click - button

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

Argument removed

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

Redeploy (private mode only)

You can redeploy already deployed contract. This is supported in a private mode only. Make sure redeployer account is deployer of already deployed one.

To redeploy contract, select deployed contract and click deploy button.

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