Search…
iOS
Sample - https://github.com/icon-project/iconex_ios/tree/master/docs/Connect/ConnectSample
ICONex Connect is a simple protocol for supporting 3rd party applications who want send transactions, ICX or IRC tokens via ICONex wallet.

Features

  • Get address of ICON wallet which managed by ICONex.
  • Request send transaction.
  • Request send ICX or IRC Token.

Basic Transmission Protocol

  • Request
Key
Type
Description
data
String
Base64 encoded string of JSON Object
caller
String
Custom URL Scheme
1
var action = [String: Any]()
2
action["id"] = 1234
3
action["method"] = "bind"
4
5
guard let data = try? JSONSerialization.data(withJSONObject: action, options: []) else { return }
6
let encoded = data.base64EncodedString()
7
8
let items = [URLQueryItem(name: "data", value: encoded), URLQueryItem(name: "caller", value: "my-app-scheme://")]
9
var component = URLComponents(string: "iconex://")!
10
component.queryItems = items
11
12
UIApplication.shared.open(component.url!, options: [:], completionHandler: nil)
Copied!
  • Response
    my-app-scheme://?data=Base64EncodedString

JSON Speicifications

API Convention

1
// Request
2
{
3
"id": $INT1,
4
"method": "$STRING1"
5
"params": {
6
"$KEY1": "$VALUE1",
7
"$KEY2": "$VALUE2",
8
...
9
}
10
}
11
12
// Response
13
{
14
"id": $INT1,
15
"code": $INT2, // if code == 1 success, else fail
16
"result": "$VALUE1"
17
}
Copied!
Key
Type
Description
Required
id
INT
Request Identifier
Required
method
String
Method for current request
Required
params
T_DATA_TYPE
Parameters for current request
Optional

Methods

Method
Description
Required Parameters
bind
Request wallet address
-
sign
Request sign for transaction
version, from, value, stepLimit, timestamp, dataType(optional), data(optional)
sendICX
Request send ICX
from, to, value
sendToken
Request send IRC token
from, to, value, contractAddress

bind

  • Return selected wallet's address.
Parameters
NULL
Returns
Selected wallet's address.
Example
1
//Request
2
{
3
"id": 1234,
4
"method" : bind
5
}
6
7
// Response - success
8
{
9
"id": 1234,
10
"code": 1,
11
"result": "hx1234..."
12
}
13
14
//Response - fail
15
{
16
"id": 1234,
17
"code": -1000,
18
"result": "Operation canceled by user."
19
}
Copied!

sign

  • Returns the signature of the transaction hash.
Parameters
Key
Type
Description
Required
version
T_INT
Protocol version ("0x3" for v3)
Required
from
T_ADDR_EOA
EOA address that created transaction
Required
to
T_ADDR_EOA
EOA address to receive coins, or SCORE address to execute the transaction.
Required
value
T_INT
Amount of ICX coins in to transfer. When omitted, assumes 0. (1 icx = 1 * 10^18 loop)
Required
stepLimit
T_INT
Maximum Step allowance that can be used by the transaction.
Required
timestamp
T_INT
Transaction creation time. timestamp is in microsecond.
Required
nid
T_INT
Network ID ("0x1" for Mainnet, "0x2" for Testnet, etc)
Required
nonce
T_INT
An arbitrary number used to prevent transaction hash collision.
Required
dataType
T_DATA_TYPE
Type of data (call, deploy or message)
Optional
data
T_DICT or String
The content of data varies depending on the dataType.
Optional
Returns
Signature of transaction hash.
Example
1
// Request
2
{
3
"id": 1234,
4
"method": "sign",
5
"params": {
6
"version": "0x3",
7
"from": "hxbe258ceb872e08851f1f59694dac2558708ece11",
8
"to": "hx5bfdb090f43a808005ffc27c25b213145e80b7cd",
9
"value": "0xde0b6b3a7640000",
10
"stepLimit": "0x12345",
11
"timestamp": "0x563a6cf330136",
12
"nid": "0x2",
13
"nonce": "0x1"
14
}
15
}
16
17
// Response - success
18
{
19
"id": 1234,
20
"code": 1,
21
"result": "SIGNED_VALUE"
22
}
23
24
// Response - fail
25
{
26
"id": 1234,
27
"code": -1000,
28
"result": "Operation canceled by user."
29
}
Copied!

sendICX

  • Send ICX via ICONex and returns transaction hash.
Parameters
Key
Type
Description
Required
from
T_ADDR_EOA
EOA address that will send ICX coins.
Required
to
T_ADDR_EOA
EOA address to receive coins.
Required
value
T_INT
Amount of ICX coins in to transfer
Required
dataType
T_DATA_TYPE
Type of data (call, deploy or message)
Optional
data
T_DICT or String
the content of data varies depending on the dataType.
Optional
Returns
Transaction hash
Example
1
// Request
2
{
3
"id": 1234,
4
"method": "sendICX",
5
"params": {
6
"to": "hxab2d8215eab14bc6bdd8bfb2c8151257032ecd8b",
7
"from": "hxbe258ceb872e08851f1f59694dac2558708ece11",
8
"value": "0x1"
9
}
10
}
11
12
// Response - success
13
{
14
"id": 1234,
15
"code": 1,
16
"result": "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
17
}
18
19
// Response - fail
20
{
21
"id": 1234,
22
"code": -1000,
23
"result": "Opertaion canceled by user."
24
}
Copied!

sendToken

  • Send IRC token via ICONex and returns transaction hash.
Parameters
Key
Type
Description
Required
from
T_ADDR_EOA
EOA address that will send IRC token.
Required
to
T_ADDR_EOA
EOA address to receive tokens.
Required
value
T_INT
Amount of IRC token
Required
contractAddress
T_ADDR_EOA
SCORE contract address
Required
Returns
Transaction hash
Example
1
// Request
2
{
3
"id": 1234,
4
"method": "sendToken",
5
"params": {
6
"from": "hxbe258ceb872e08851f1f59694dac2558708ece11",
7
"to": "hxab2d8215eab14bc6bdd8bfb2c8151257032ecd8b",
8
"value": "0x1",
9
"contractAddress": "cxb0776ee37f5b45bfaea8cff1d8232fbb6122ec32"
10
}
11
}
12
13
// Response - success
14
{
15
"id": 1234,
16
"code": 1,
17
"result": "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
18
}
19
20
// Response - fail
21
{
22
"id": 1234,
23
"code": -1000,
24
"result": "Opertaion canceld by user"
25
}
Copied!

Error Code

Code
Message
Description
-1000
Operation canceld by user.
User cancel
-1001
Parse error (Invalid JSON type)
Data is not a JSON type
-1002
Invalid request.
JSON must contains required parameters.
-1003
Invalid method
Invalid method
-1004
Not found caller.
Could not found caller in request.
-2001
ICONex has no ICX wallet.
ICONex has no ICX wallet for support.
-2002
Not found parameter. ('$key')
$key is not found in "params"
-3001
Could not find matched wallet. ('$address')
There is no wallet matched with given address.
-3002
Sending and receiving address are same.
Sending and receiving address are same.
-3003
Insufficient balance.
Requested value is bigger than balance.
-3004
Insufficient balance for fee.
Insufficient balance for fee.
-3005
Invalid parameter. ('$key')
Something is wrong with value.
-4001
Failed to sign.
Error occurs while signing
-9999
Somethings wrong with network ($message)
All errors while networking. $message may contains the reason of error.
Last modified 13d ago