ICON Developer Portal

ICON Developer Portal

ICON Network is a decentralized smart contract protocol based on ‘loopchain’, a high-performance blockchain engine. The ICON Network aims to remove barriers among different blockchains and allow them to exchange values without intermediaries. By realizing this goal, ICON will realize the mass adoption of blockchain technology and Hyperconnect the World.

Get Started

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
KeyTypeDescription
dataStringBase64 encoded string of JSON Object
callerStringCustom URL Scheme
var action = [String: Any]()
action["id"] = 1234
action["method"] = "bind"

guard let data = try? JSONSerialization.data(withJSONObject: action, options: []) else { return }
let encoded = data.base64EncodedString()

let items = [URLQueryItem(name: "data", value: encoded), URLQueryItem(name: "caller", value: "my-app-scheme://")]
var component = URLComponents(string: "iconex://")!
component.queryItems = items

UIApplication.shared.open(component.url!, options: [:], completionHandler: nil)
  • Response
    my-app-scheme://?data=Base64EncodedString

JSON Speicifications

API Convention

// Request
{
    "id": $INT1,
    "method": "$STRING1"
    "params": {
        "$KEY1": "$VALUE1",
        "$KEY2": "$VALUE2",
        ...
    }
}

// Response
{
    "id": $INT1,
    "code": $INT2,    // if code == 1 success, else fail
    "result": "$VALUE1"
}
KeyTypeDescriptionRequired
idINTRequest IdentifierRequired
methodStringMethod for current requestRequired
paramsT_DATA_TYPEParameters for current requestOptional

Methods

MethodDescriptionRequired Parameters
bindRequest wallet address-
signRequest sign for transactionversion, from, value, stepLimit, timestamp, dataType(optional), data(optional)
sendICXRequest send ICXfrom, to, value
sendTokenRequest send IRC tokenfrom, to, value, contractAddress

bind

  • Return selected wallet's address.

Parameters

NULL

Returns

Selected wallet's address.

Example

//Request
{
    "id": 1234,
    "method" : bind
}

// Response - success
{
    "id": 1234,
    "code": 1,
    "result": "hx1234..."
}

//Response - fail
{
    "id": 1234,
    "code": -1000,
    "result": "Operation canceled by user."
}

sign

  • Returns the signature of the transaction hash.

Parameters

KeyTypeDescriptionRequired
versionT_INTProtocol version ("0x3" for v3)Required
fromT_ADDR_EOAEOA address that created transactionRequired
toT_ADDR_EOAEOA address to receive coins, or SCORE address to execute the transaction.Required
valueT_INTAmount of ICX coins in to transfer. When omitted, assumes 0. (1 icx = 1 * 10^18 loop)Required
stepLimitT_INTMaximum Step allowance that can be used by the transaction.Required
timestampT_INTTransaction creation time. timestamp is in microsecond.Required
nidT_INTNetwork ID ("0x1" for Mainnet, "0x2" for Testnet, etc)Required
nonceT_INTAn arbitrary number used to prevent transaction hash collision.Required
dataTypeT_DATA_TYPEType of data (call, deploy or message)Optional
dataT_DICT or StringThe content of data varies depending on the dataType.Optional

Returns

Signature of transaction hash.

Example

// Request
{
    "id": 1234,
    "method": "sign",
    "params": {
        "version": "0x3",
        "from": "hxbe258ceb872e08851f1f59694dac2558708ece11",
        "to": "hx5bfdb090f43a808005ffc27c25b213145e80b7cd",
        "value": "0xde0b6b3a7640000",
        "stepLimit": "0x12345",
        "timestamp": "0x563a6cf330136",
        "nid": "0x2",
        "nonce": "0x1"
    }
}

// Response - success
{
    "id": 1234,
    "code": 1,
    "result": "SIGNED_VALUE"
}

// Response - fail
{
    "id": 1234,
    "code": -1000,
    "result": "Operation canceled by user."
}

sendICX

  • Send ICX via ICONex and returns transaction hash.

Parameters

KeyTypeDescriptionRequired
fromT_ADDR_EOAEOA address that will send ICX coins.Required
toT_ADDR_EOAEOA address to receive coins.Required
valueT_INTAmount of ICX coins in to transferRequired
dataTypeT_DATA_TYPEType of data (call, deploy or message)Optional
dataT_DICT or Stringthe content of data varies depending on the dataType.Optional

Returns

Transaction hash

Example

// Request
{
    "id": 1234,
    "method": "sendICX",
    "params": {
            "to": "hxab2d8215eab14bc6bdd8bfb2c8151257032ecd8b",
            "from": "hxbe258ceb872e08851f1f59694dac2558708ece11",
            "value": "0x1"
        }
}

// Response - success
{
    "id": 1234,
    "code": 1,
    "result": "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
}

// Response - fail
{
    "id": 1234,
    "code": -1000,
    "result": "Opertaion canceled by user."
}

sendToken

  • Send IRC token via ICONex and returns transaction hash.

Parameters

KeyTypeDescriptionRequired
fromT_ADDR_EOAEOA address that will send IRC token.Required
toT_ADDR_EOAEOA address to receive tokens.Required
valueT_INTAmount of IRC tokenRequired
contractAddressT_ADDR_EOASCORE contract addressRequired

Returns

Transaction hash

Example

// Request
{
    "id": 1234,
    "method": "sendToken",
    "params": {
            "from": "hxbe258ceb872e08851f1f59694dac2558708ece11",
            "to": "hxab2d8215eab14bc6bdd8bfb2c8151257032ecd8b",
            "value": "0x1",
            "contractAddress": "cxb0776ee37f5b45bfaea8cff1d8232fbb6122ec32"
        }
}

// Response - success
{
    "id": 1234,
    "code": 1,
    "result": "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
}

// Response - fail
{
    "id": 1234,
    "code": -1000,
    "result": "Opertaion canceld by user"
}

Error Code

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

Updated 11 months ago

iOS


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.