Broker API
The Broker API is a standalone client that exposes Broker functionality via a JSON API interface.
Brokers need to run the client for the API themselves, as the Broker holds keys used to sign extrinsics and collect any fees set for Deposit Channels. The API client works by pointing it to an RPC node — also run by the same Broker, ideally.
Command line arguments and defaults
- The
state_chain.ws_endpoint
should point at a synced Chainflip State Chain RPC node. The default isws://localhost:9944
assuming it is run locally. - The
state_chain.signing_key_file
should be the Broker's private key for their on-chain account. The account should be funded (opens in a new tab). The account type should be set to Broker. The default is/etc/chainflip/keys/signing_key_file
. - The
port
is the port on which the Broker will listen for connections. Use0
to assign a random port. The default is80
.
./chainflip-broker-api --help
chainflip-broker-api
USAGE:
chainflip-broker-api [OPTIONS]
OPTIONS:
-h, --help
Print help information
--port <PORT>
The port number on which the broker will listen for connections. Use 0 to assing a
random port. [default: 80]
--state_chain.signing_key_file <SIGNING_KEY_FILE>
A path to a file that contains the broker's secret key for signing extrinsics.
[default: /etc/chainflip/keys/signing_key_file]
--state_chain.ws_endpoint <WS_ENDPOINT>
The state chain node's rpc endpoint. [default: ws://localhost:9944]
-v, --version
Print the version of the API
RPC Methods
broker_request_swap_deposit_address
Parameters:
source_asset
: Source asset.destination_asset
: Egress asset.destination_address
: Egress Address.broker_commission_bps
: Broker Commission in basis points (100th of a percent). Broker operators can choose to charge a fee for the use of their endpoint, and can be set at any value from 1 basis point to 1000 basis points.channel_metadata
: (Optional) Cross-chain message metadata as a JSON object:{"gas_budget": <amount>, "message":<hex_string>, "cf_parameters": <hex_string>}
. Wheremessage
andcf_parameters
are hex encoded strings.
Return:
- deposit address.
broker_register_account
Parameters:
None
Return:
null
if successful, otherwise an error.
Working Example
This example assumes the node that is exposing the Statechain RPC's is funded.
- Open a terminal and run:
./chainflip-broker-api \
--state_chain.ws_endpoint=ws://localhost:9944 \
--state_chain.signing_key_file /path/to/my/signing_key \
--port 62378 # or whatever port you want to use
It will print 🎙 Server is listening on 0.0.0.0:62378.
and continue to run.
- Open another terminal and run: Register as a broker if you are not already.
curl -H "Content-Type: application/json" \
-d '{"id":1, "jsonrpc":"2.0", "method": "broker_register_account"}' \
http://localhost:62378
- Request a swap deposit address:
curl -H "Content-Type: application/json" \
-d '{"id":1, "jsonrpc":"2.0", "method": "broker_request_swap_deposit_address", "params": ["ETH", "FLIP","0xabababababababababababababababababababab", 0]}' \
http://localhost:62378
The result is the hex encoded deposit address, channel id, expiry block, and the issued block:
{
"jsonrpc":"2.0",
"result":{
"address":"0xe720e23f62efc931d465a9d16ca303d72ad6c0bc",
"issued_block":5418,
"channel_id":6,
"source_chain_expiry_block":2954
},
"id":1
}
Limitations
- It doesn't seem to work with
wss
, so make sure the address is specified withws
. It should be ok since we're not going to expose this externally.
Reference
Assets
Assets are specified as a { chain, asset }
object, where the chain is as described below, and the asset is an upper-case string.
Where the chain is unambiguous (for example for the native currencies), the asset can be submitted simply as the upper-case string.
For example, for BTC, "BTC"
and { chain: "Bitcoin", asset: "BTC" }
are both valid and resolve to the same asset.
Assets returned from the RPCs will always take the explicit form, for example { chain: "Ethereum", asset: "ETH" }
Chains
Chains are specified as the full name of the chain, capitalised, for example "Ethereum"
, "Bitcoin"
, "Polkadot"
.
Addresses
Addresses should be encoded according to their host chains:
- Ethereum addresses should be encoded as Hex strings, for example
"0xfa36e03defc6e4d140cc61fcaab9d1fbef18642f"
. - Polkadot addresses can be encoded using SS58 or Hex strings, for example:
"13zyEWmmLDx63Y99TL9SkxBe1DqPVCrcjXytxM3ZHGRyEJV5"
or"0x84aec0876dbb3cb7391eeded2eef5fbcf0d1a34f7c9f86f9af205f944b461761"
- Bitcoin addresses should be encoded using the appropriate bitcoin standard for the address type. For example
"tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx"
is a valid bech32 address on Bitcoin testnet.