Smart Contracts

Prepare solidity compiler

Usage: ioctl contract prepare
1
➜ ioctl contract prepare
2
3
...
4
Solidity compiler is ready now.
Copied!
This process installs solc to you env. You can also install it by using the following commands.
On Ubuntu, you can use the following command
1
sudo add-apt-repository ppa:ethereum/ethereum
2
sudo apt-get update
3
sudo apt-get install solc
Copied!
On macOS, you can use the following command
1
brew update
2
brew upgrade
3
brew tap ethereum/ethereum
4
brew install [email protected]
Copied!
For more detailed instruction of installing solc, please refer to https://solidity.readthedocs.io/en/v0.5.0/installing-solidity.html.
Please note that ioctl currently supports solc 4.x and 5.x. Please make sure you install the current version.

Compile smart contract

Usage: ioctl contract compile CONTRACT_NAME [CODE_FILES...] [--abi-out ABI_PATH] [--bin-out BIN_PATH]
1
➜ ioctl contract compile Multisend
2
Output:
3
======= multisend2.sol:Multisend =======
4
Binary:
5
0x608060405234801561001057600080fd5b5060405160408061096483398101604052805160209091015160008054600160a060020a03191633179055600191909155600255610911806100536000396000f30060806...
6
Contract JSON ABI
7
[{"constant":false,"inputs":[{"name":"recipients","type":"address[]"},{"name":"amounts","type":"uint256[]"},{"name":"payload","type":"string"}],"name":"sendCoin","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},
8
...
Copied!

Deploy smart contract from sol file

Usage: ioctl contract deploy sol CONTRACT_NAME [CODE_FILES...] [--with-arguments INIT_INPUT]
1
➜ ioctl contract deploy sol Multisend --with-arguments '{"_minTips":1,"_limit":20}' -s yqr
2
Output:
3
...
4
Action has been sent to blockchain.
5
Wait for several seconds and query this action by hash:iotexscan.io/action/xxx...
Copied!

Deploy smart contract from bytecode

Usage: ioctl contract deploy bytecode BYTECODE [ABI_PATH INIT_INPUT]
1
➜ ioctl contract deploy bytecode 60806040523480156100105760008... -s yqr
2
Output:
3
...
4
version: 1 nonce: 144 gasLimit: 745466 gasPrice: 0.000001 IOTX
5
senderAddress: io1cl6rl2ev5dfa988qmgzg2x4hfazmp9vn2g66ng (yqr)
6
execution: <
7
contract:
8
data: 608060405234801561001057600080fd5b5060405160408061096483398101604052805160209091015160008054600160a060020a03191633179055600191909155600255610911806100536000396000f300608060405260043610
9
...
10
>
11
senderPubKey: 046d89e514d67b702d0a4bf15bfa32f2ffac43ab56f9c9a3a0020b3cd02c426267dd8a5a03bca5c2fe2487fd0e1539b8d25053ba1fc9db83684ea7a33b70f936f7
12
signature: f436c1ffadd63bf67308d8416529aac04deeb0761022aa5d75a60869e91dc5ab4dd64576d82ffe1a40e569450c6463accbbe2b9cf9251b0577419f6a6995e48800
13
14
Please confirm your action.
15
16
17
Options: yes
18
Quit for anything else.
19
yes
20
Action has been sent to blockchain.
21
Wait for several seconds and query this action by hash:iotexscan.io/action/xxx...
Copied!

Deploy smart contract from bin file

Usage: ioctl contract deploy bin BIN_PATH [ABI_PATH INIT_INPUT]
1
➜ ioctl contract deploy bin a.bin a.abi '{"_minTips":1,"_limit":20}' -s yqr
2
Output:
3
...
4
version: 1 nonce: 143 gasLimit: 781866 gasPrice: 0.000001 IOTX
5
senderAddress: io1cl6rl2ev5dfa988qmgzg2x4hfazmp9vn2g66ng (yqr)
6
execution: <
7
contract:
8
data: 608060405234801561001057600080fd5b5060405160408061096483398101604052805160209091015160008054600160a060020a03191633179055600191909155600255610911806100536000396000f300608060405260043610
9
...
10
>
11
senderPubKey: 046d89e514d67b702d0a4bf15bfa32f2ffac43ab56f9c9a3a0020b3cd02c426267dd8a5a03bca5c2fe2487fd0e1539b8d25053ba1fc9db83684ea7a33b70f936f7
12
signature: 310b186c59563eb1e261465b9e28a325149267e10afed988e697272f5411defc7c1cc419f01c6fbb45e4fbb2f50bcdbfb63fec7bd5e1a0f9ec43d6fcc286462a01
13
14
Please confirm your action.
15
16
17
Options: yes
18
Quit for anything else.
19
yes
20
Action has been sent to blockchain.
21
Wait for several seconds and query this action by hash:iotexscan.io/action/xxx...
Copied!

Invoke smart contract by function

Usage: ioctl contract invoke function (CONTRACT_ADDRESS|ALIAS) ABI_PATH FUNCTION_NAME [AMOUNT_IOTX] [--with-arguments INVOKE_INPUT]
1
→ ioctl contract invoke function io1h8z... a.abi sendCoin 2 --with-arguments {"recipients":["io1h8zxmdacge966wp6t90a02ncghaa6eptnftfqr","io14fmlh7zedcx7tn3k9k744v54nxnv8zky86tjhj"],"amounts":["312","123"],"payload":"PLEASE!!!"}
2
Output:
3
version: 1 nonce: 146 gasLimit: 45600 gasPrice: 0.000001 IOTX
4
senderAddress: io1cl6rl2ev5dfa988qmgzg2x4hfazmp9vn2g66ng (yqr)
5
execution: <
6
contract: io1h8zxmdacge966wp6t90a02ncghaa6eptnftfqr (m)
7
amount: 2 IOTX
8
data: 02c4bc47000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000
9
...
Copied!

Invoke smart contract by bytecode

Usage: ioctl contract invoke bytecode (CONTRACT_ADDRESS|ALIAS) PACKED_ARGUMENTS [AMOUNT_IOTX]
1
→ ioctl contract invoke bytecode io1hp6y... b5060409 0 -s yqr -l 1000000
2
Output:
3
version: 1 nonce: 1 gasLimit: 1000000 gasPrice: 0.000001 IOTX
4
senderAddress: io1a8r9fvu6e3vthfaqvnxlhc6eavsm6t8a2cwtud (devaccount)
5
execution: <
6
contract: io1hp6y4eqr90j7tmul4w2wa8pm7wx462hq0mg4tw
7
data: b5060409
8
...
Copied!

Test smart contract by bytecode

Usage: ioctl contract test bytecode (CONTRACT_ADDRESS|ALIAS) PACKED_ARGUMENTS [AMOUNT_IOTX]
1
→ ioctl contract test bytecode io18qq... a4d66daf
2
Output:
3
return 0000000000000000000000000000000000000000000000000000000000000000
Copied!

Test smart contract by function

Usage: ioctl contract test function (CONTRACT_ADDRESS|ALIAS) ABI_PATH FUNCTION_NAME [AMOUNT_IOTX] [--with-arguments INVOKE_INPUT]
1
→ ioctl contract test function io18qq... a.abi owner
2
Output:
3
return 000000000000000000000000c7f43fab2ca353d29ce0da04851ab74f45b09593
Copied!

Share local files with IoTeX IDE

Usage: ioctl contract share LOCAL_FOLDER_PATH [--iotex-ide YOUR_IOTEX_IDE_URL_INSTANCE]
LOCAL_FOLDER_PATH can be absolute or relatively. --iotex-ide flag defaults to https://ide.iotex.io.
1
→ ioctl contract share ioctl
2
Output:
3
2020/08/22 16:45:00 Listening on 127.0.0.1:65520, Please open your IDE ( https://ide.iotex.io ) to connect to local files
4
2020/08/22 16:45:05 share :ioctl/client.go
5
2020/08/22 16:45:05 share :ioctl/cmd/account/account.go
6
2020/08/22 16:45:05 share :ioctl/cmd/account/account_test.go
7
2020/08/22 16:45:05 share :ioctl/cmd/account/accountbalance.go
8
...
Copied!
Last modified 6mo ago