Address & XPUB

Get Address

You can get address of account using getAddress() function.

var coinType = DcentWebConnector.coinType.ETHEREUM
var keyPath = "m/44'/60'/0'/0/0" // key path of the account

var result
try{
    // Get Ethereum Address corresponding to keyPath
    result = await DcentWebConnector.getAddress(coinType, keyPath)
}catch(e){
    result = e
}

Returned response object has:

{
    "header": {
        "version": "1.0",
        "response_from": "ethereum",
        "status": "success"
    },
    "body": {
        "command": "get_address",
        "parameter": {
            "address": "0x354609C4c9a15d4265cF6D94010568D5Cf4d0c1B"
        }
    }
}

The address string format is depend on the coin type.

For ss58 addresses used by the Substrate ecosystems such as Astar, prefix is added. The value of prefix is the prefix for each network defined in ss58-registry.

var coinType = DcentWebConnector.coinType.PARA
var keyPath = "m/44'/810'/0'/0/0" // key path of the Astar's account
var prefix = 5 // The address prefix of Astar

var result
try{
    // Get the address corresponding to keyPath & prefix
    result = await DcentWebConnector.getAddress(coinType, keyPath, prefix)
}catch(e){
    result = e
}

Please note that Astar EVM features an EVM (Ethereum Virtual Machine) compatible runtime environment, so it is the same as getting the address of ETHEREUM account.

Returned response object has:

{
    "header": {
        "version": "1.0",
        "response_from": "para",
        "status": "success"
    },
    "body": {
        "command": "get_address",
        "parameter": {
            "address": "YzsEz5dG8TDqG49pGaejLrFoD4oeNTEX7yWt4qcCV4TA9LB"
        }
    }
}

Get XPUB

You can get xpub using getXPUB() function. The BIP32 key path must be at least 2 depth or more.

var keyPath = "m/44'/0'" // key path of the account

var result
try{
    // Get extended public key corresponding to keyPath
    result = await DcentWebConnector.getXPUB(keyPath)
}catch(e){
    result = e
}

Returned response object has:

{
    "header": {
        "version": "1.0",
        "response_from": "coin",
        "status": "success"
    },
    "body": {
        "command": "xpub",
        "parameter": {
            "public_key": "xpub6Bp87egy.....EdAH4sMeqY3"
        }
    }
}

The public_key is xpub value.

Select Address

Show you address list and you can select an address using selectAddress() function.

var result
try{
    // Get extended public key corresponding to keyPath
    let addresses = [
        {
            address: '0x1234567812345678123456781234567812345678',
            path: `m'/44'/60'/0'/0/0`
        },
        {
            address: '0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd',
            path: `m'/44'/8217'/0'/0/0`
        }
    ]
    result = await DcentWebConnector.selectAddress(addresses)
}catch(e){
    result = e
}

Returned response object has:

{
    "header": {
        "version": "1.0",
        "response_from": "bridge",
        "status": "success"
    },
    "body": {
        "command": "select_address",
        "parameter": {
            "selected_index": 0,
            "selected_address": {
                "address": "0x1234567812345678123456781234567812345678",
                "path": "m'/44'/60'/0'/0/0"
            }
        }
    }
}

The 'selectedIndex' is index of addresses array.

Last updated