Search…
Android
Sample - https://github.com/icon-project/iconex_android/tree/master/sample_iconex_connect
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
From Package name
receiver
String
From Receiver class name
1
JSONObject action = new JSONObject();
2
try {
3
action.put("id", 1234);
4
action.put("method", "bind");
5
} catch (JSONException e) {
6
return;
7
}
8
9
String data = Base64.encodeToString(action.toString().getBytes(), Base64.NO_WRAP);
10
11
Intent intent = new Intent()
12
.setClassName("foundation.icon.iconex", "foundation.icon.connect.ConnectReceiver")
13
.setAction("ICON_CONNECT")
14
.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
15
.putExtra("data", data)
16
.putExtra("from", fromPackageName)
17
.putExtra("receiver", fromReceiverName);
18
19
sendBroadcast(intent);
Copied!
    Response
Key
Type
Description
data
String
Base64 encoded string of JSON Object
1
String data = intent.getStringExtra("data");
2
byte[] base64Response = Base64.decode(resp, Base64.NO_WRAP);
3
4
try {
5
JSONObject response = new JSONObject(new String(base64Response));
6
} catch (JSONException e) {
7
}
Copied!

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 4mo ago