The RPC module provides a set of APIs for developers to interact with FNN. Please note that APIs are not stable yet and may change in the future.
Allowing arbitrary machines to access the JSON-RPC port (using the rpc.listening_addr
configuration option) is dangerous and strongly discouraged. Please strictly limit the access to only trusted machines.
You may refer to the e2e test cases in the tests/bruno/e2e
directory for examples of how to use the RPC.
RPC module for cross chain hub demonstration. This is the seccond line
Send BTC to a address.
btc_pay_req
- String, Bitcoin payment request stringcurrency
- Currency, Request currency
timestamp
- u64, Seconds since epoch when the order is createdexpiry
- u64, Seconds after timestamp that the order expiresckb_final_tlc_expiry_delta
- u64, The minimal expiry in seconds of the final TLC in the CKB networkcurrency
- Currency, Request currencywrapped_btc_type_script
- ckb_jsonrpc_types::Script, Wrapped BTC type scriptbtc_pay_req
- String, Payment request for BTCckb_pay_req
- String, Payment request for CKBpayment_hash
- String, Payment hash for the HTLC for both CKB and BTC.amount_sats
- u128, Amount required to pay in Satoshis, including feefee_sats
- u128, Fee in Satoshisstatus
- CchOrderStatus, Order status
Receive BTC from a payment hash.
payment_hash
- String, Payment hash for the HTLC for both CKB and BTC.channel_id
- Hash256, Channel ID for the CKB payment.amount_sats
- u128, How many satoshis to receive, excluding cross-chain hub fee.final_tlc_expiry
- u64, Expiry set for the HTLC for the CKB payment to the payee.
timestamp
- u64, Seconds since epoch when the order is createdexpiry
- u64, Seconds after timestamp that the order expiresckb_final_tlc_expiry_delta
- u64, The minimal expiry in seconds of the final TLC in the CKB networkwrapped_btc_type_script
- ckb_jsonrpc_types::Script, Wrapped BTC type scriptbtc_pay_req
- String, Payment request for BTCpayment_hash
- String, Payment hash for the HTLC for both CKB and BTC.channel_id
- Hash256, Channel ID for the CKB payment.tlc_id
-Option<u64>
, TLC ID for the CKB payment.amount_sats
- u128, Amount will be received by the payeefee_sats
- u128, Fee in Satoshisstatus
- CchOrderStatus, Order status
Get receive BTC order by payment hash.
payment_hash
- String, Payment hash for the HTLC for both CKB and BTC.
timestamp
- u64, Seconds since epoch when the order is createdexpiry
- u64, Seconds after timestamp that the order expiresckb_final_tlc_expiry_delta
- u64, The minimal expiry in seconds of the final TLC in the CKB networkwrapped_btc_type_script
- ckb_jsonrpc_types::Script, Wrapped BTC type scriptbtc_pay_req
- String, Payment request for BTCpayment_hash
- String, Payment hash for the HTLC for both CKB and BTC.channel_id
- Hash256, Channel ID for the CKB payment.tlc_id
-Option<u64>
, TLC ID for the CKB payment.amount_sats
- u128, Amount will be received by the payeefee_sats
- u128, Fee in Satoshisstatus
- CchOrderStatus, Order status
RPC module for channel management.
Attempts to open a channel with a peer.
peer_id
- PeerId, The peer ID to open a channel with.funding_amount
- u128, The amount of CKB or UDT to fund the channel with.public
-Option<bool>
, Whether this is a public channel (will be broadcasted to network, and can be used to forward TLCs), an optional parameter, default value is true.funding_udt_type_script
-Option<Script>
, The type script of the UDT to fund the channel with, an optional parameter.shutdown_script
-Option<Script>
, The script used to receive the channel balance, an optional parameter, default value is the secp256k1_blake160_sighash_all script corresponding to the configured private key.commitment_delay_epoch
-Option<EpochNumberWithFraction>
, The delay time for the commitment transaction, must be an EpochNumberWithFraction in u64 format, an optional parameter, default value is 24 hours.commitment_fee_rate
-Option<u64>
, The fee rate for the commitment transaction, an optional parameter.funding_fee_rate
-Option<u64>
, The fee rate for the funding transaction, an optional parameter.tlc_expiry_delta
-Option<u64>
, The expiry delta to forward a tlc, in milliseconds, default to 1 day, which is 24 * 60 * 60 * 1000 milliseconds This parameter can be updated with rpcupdate_channel
later.tlc_min_value
-Option<u128>
, The minimum value for a TLC our side can receive an optional parameter, default is 0, which means we can receive any TLC is larger than 0. This parameter can be updated with rpcupdate_channel
later.tlc_fee_proportional_millionths
-Option<u128>
, The fee proportional millionths for a TLC, Proportional to the amount of the forwarded tlc. The unit is millionths of the amount. default is 1000 which means 0.1%. This parameter can be updated with rpcupdate_channel
later.max_tlc_value_in_flight
-Option<u128>
, The maximum value in flight for TLCs, an optional parameter. This parameter can not be updated after channel is opened.max_tlc_number_in_flight
-Option<u64>
, The maximum number of TLCs that can be accepted, an optional parameter, default is 125 This parameter can not be updated after channel is opened.
temporary_channel_id
- Hash256, The temporary channel ID of the channel being opened
Accepts a channel opening request from a peer.
temporary_channel_id
- Hash256, The temporary channel ID of the channel to acceptfunding_amount
- u128, The amount of CKB or UDT to fund the channel withshutdown_script
-Option<Script>
, The script used to receive the channel balance, an optional parameter, default value is the secp256k1_blake160_sighash_all script corresponding to the configured private keymax_tlc_value_in_flight
-Option<u128>
, The max tlc sum value in flight for the channel, default is u128::MAX This parameter can not be updated after channel is opened.max_tlc_number_in_flight
-Option<u64>
, The max tlc number in flight send from our side, default is 125 This parameter can not be updated after channel is opened.tlc_min_value
-Option<u128>
, The minimum value for a TLC our side can receive an optional parameter, default is 0, which means we can receive any TLC is larger than 0. This parameter can be updated with rpcupdate_channel
later.tlc_fee_proportional_millionths
-Option<u128>
, The fee proportional millionths for a TLC, Proportional to the amount of the forwarded tlc. The unit is millionths of the amount. default is 1000 which means 0.1%. This parameter can be updated with rpcupdate_channel
later.tlc_expiry_delta
-Option<u64>
, The expiry delta to forward a tlc, in milliseconds, default to 1 day, which is 24 * 60 * 60 * 1000 milliseconds This parameter can be updated with rpcupdate_channel
later.
channel_id
- Hash256, The final ID of the channel that was accepted, it's different from the temporary channel ID
Lists all channels.
peer_id
-Option<PeerId>
, The peer ID to list channels for, an optional parameter, if not provided, all channels will be listed
channels
-Vec<Channel>
, The list of channels
Sends a commitment_signed message to the peer.
channel_id
- Hash256, The channel ID of the channel to send the commitment_signed message to
- None
Adds a TLC to a channel.
channel_id
- Hash256, The channel ID of the channel to add the TLC toamount
- u128, The amount of the TLCpayment_hash
- Hash256, The payment hash of the TLCexpiry
- u64, The expiry of the TLChash_algorithm
-Option<HashAlgorithm>
, The hash algorithm of the TLC
tlc_id
- u64, The ID of the TLC
Removes a TLC from a channel.
channel_id
- Hash256, The channel ID of the channel to remove the TLC fromtlc_id
- u64, The ID of the TLC to removereason
- RemoveTlcReason, The reason for removing the TLC, either a 32-byte hash for preimage fulfillment or an u32 error code for removal
- None
Shuts down a channel.
channel_id
- Hash256, The channel ID of the channel to shut downclose_script
- Script, The script used to receive the channel balance, only support secp256k1_blake160_sighash_all script for nowforce
-Option<bool>
, Whether to force the channel to closefee_rate
- u64, The fee rate for the closing transaction, the fee will be deducted from the closing initiator's channel balance
- None
Updates a channel.
channel_id
- Hash256, The channel ID of the channel to updateenabled
-Option<bool>
, Whether the channel is enabledtlc_expiry_delta
-Option<u64>
, The CLTV delta from the current height that should be used to set the timelock for the final hop
The expiry delta for the TLC locktime
tlc_minimum_value
-Option<u128>
, The minimum value for a TLCtlc_fee_proportional_millionths
-Option<u128>
, The fee proportional millionths for a TLC
- None
Sends a payment to a peer.
target_pubkey
-Option<Pubkey>
, the identifier of the payment targetamount
-Option<u128>
, the amount of the paymentpayment_hash
-Option<Hash256>
, the hash to use within the payment's HTLCfinal_tlc_expiry_delta
-Option<u64>
, the TLC expiry delta should be used to set the timelock for the final hop, in millisecondstlc_expiry_limit
-Option<u64>
, the TLC expiry limit for the whole payment, in millisecondsinvoice
-Option<String>
, the encoded invoice to send to the recipienttimeout
-Option<u64>
, the payment timeout in seconds, if the payment is not completed within this time, it will be cancelledmax_fee_amount
-Option<u128>
, the maximum fee amounts in shannons that the sender is willing to paymax_parts
-Option<u64>
, max parts for the payment, only used for multi-part paymentskeysend
-Option<bool>
, keysend paymentudt_type_script
-Option<Script>
, udt type script for the paymentallow_self_payment
-Option<bool>
, allow self payment, default is falsedry_run
-Option<bool>
, dry_run for payment, used for check whether we can build valid router and the fee for this payment, it's useful for the sender to double check the payment before sending it to the network, default is false
payment_hash
- Hash256, The payment hash of the paymentstatus
- PaymentSessionStatus, The status of the paymentcreated_at
- u64, The time the payment was created at, in milliseconds from UNIX epochlast_updated_at
- u64, The time the payment was last updated at, in milliseconds from UNIX epochfailed_error
-Option<String>
, The error message if the payment failedfee
- u128, fee paid for the payment
Retrieves a payment.
payment_hash
- Hash256, The payment hash of the payment to retrieve
payment_hash
- Hash256, The payment hash of the paymentstatus
- PaymentSessionStatus, The status of the paymentcreated_at
- u64, The time the payment was created at, in milliseconds from UNIX epochlast_updated_at
- u64, The time the payment was last updated at, in milliseconds from UNIX epochfailed_error
-Option<String>
, The error message if the payment failedfee
- u128, fee paid for the payment
RPC module for graph management.
Get the list of nodes in the network graph.
limit
-Option<u64>
, The maximum number of nodes to return.after
-Option<JsonBytes>
, The cursor to start returning nodes from.
nodes
-Vec<NodeInfo>
, The list of nodes.last_cursor
- JsonBytes, The last cursor.
Get the list of channels in the network graph.
limit
-Option<u64>
, The maximum number of channels to return.after
-Option<JsonBytes>
, The cursor to start returning channels from.
channels
-Vec<ChannelInfo>
, A list of channels.last_cursor
- JsonBytes, The last cursor for pagination.
The RPC module for node information.
Get the node information.
- None
version
- String, The version of the node software.commit_hash
- String, The commit hash of the node software.public_key
- Pubkey, The public key of the node.node_name
-Option<String>
, The optional name of the node.peer_id
- PeerId, The peer ID of the node, serialized as a string.addresses
-Vec<MultiAddr>
, A list of multi-addresses associated with the node.chain_hash
- Hash256, The hash of the blockchain that the node is connected to.open_channel_auto_accept_min_ckb_funding_amount
- u64, The minimum CKB funding amount for automatically accepting open channel requests, serialized as a hexadecimal string.auto_accept_channel_ckb_funding_amount
- u64, The CKB funding amount for automatically accepting channel requests, serialized as a hexadecimal string.tlc_expiry_delta
- u64, The locktime expiry delta for Time-Locked Contracts (TLC), serialized as a hexadecimal string.tlc_min_value
- u128, The minimum value for Time-Locked Contracts (TLC), serialized as a hexadecimal string.tlc_max_value
- u128, The maximum value for Time-Locked Contracts (TLC), serialized as a hexadecimal string,0
means no maximum value limit.tlc_fee_proportional_millionths
- u128, The fee proportional to the value of Time-Locked Contracts (TLC), expressed in millionths and serialized as a hexadecimal string.channel_count
- u32, The number of channels associated with the node, serialized as a hexadecimal string.pending_channel_count
- u32, The number of pending channels associated with the node, serialized as a hexadecimal string.peers_count
- u32, The number of peers connected to the node, serialized as a hexadecimal string.network_sync_status
- String, The synchronization status of the node within the network.udt_cfg_infos
- UdtCfgInfos, Configuration information for User-Defined Tokens (UDT) associated with the node.
RPC module for invoice management.
Generates a new invoice.
amount
- u128, The amount of the invoice.description
-Option<String>
, The description of the invoice.currency
- Currency, The currency of the invoice.payment_preimage
- Hash256, The payment preimage of the invoice.expiry
-Option<u64>
, The expiry time of the invoice.fallback_address
-Option<String>
, The fallback address of the invoice.final_expiry_delta
-Option<u64>
, The final HTLC timeout of the invoice.udt_type_script
-Option<Script>
, The UDT type script of the invoice.hash_algorithm
-Option<HashAlgorithm>
, The hash algorithm of the invoice.
invoice_address
- String, The encoded invoice address.invoice
- CkbInvoice, The invoice.
Parses a encoded invoice.
invoice
- String, The encoded invoice address.
invoice
- CkbInvoice, The invoice.
Retrieves an invoice.
payment_hash
- Hash256, The payment hash of the invoice.
invoice_address
- String, The encoded invoice address.invoice
- CkbInvoice, The invoice.status
- CkbInvoiceStatus, The invoice status
Cancels an invoice, only when invoice is in status Open
can be canceled.
payment_hash
- Hash256, The payment hash of the invoice.
invoice_address
- String, The encoded invoice address.invoice
- CkbInvoice, The invoice.status
- CkbInvoiceStatus, The invoice status
RPC module for peer management.
Connect to a peer.
address
- MultiAddr, The address of the peer to connect to.save
-Option<bool>
, Whether to save the peer address to the peer store.
- None
Disconnect from a peer.
peer_id
- PeerId, The peer ID of the peer to disconnect.
- None
The state of a channel
NegotiatingFunding
- NegotiatingFundingFlags, We are negotiating the parameters required for the channel prior to funding it.CollaboratingFundingTx
- CollaboratingFundingTxFlags, We're collaborating with the other party on the funding transaction.SigningCommitment
- SigningCommitmentFlags, We have collaborated over the funding and are now waiting for CommitmentSigned messages.AwaitingTxSignatures
- AwaitingTxSignaturesFlags, We've received and sentcommitment_signed
and are now waiting for both party to collaborate on creating a valid funding transaction.AwaitingChannelReady
- AwaitingChannelReadyFlags, We've received/sentfunding_created
andfunding_signed
and are thus now waiting on the funding transaction to confirm.ChannelReady
- , Both we and our counterparty consider the funding transaction confirmed and the channel is now operational.ShuttingDown
- ShuttingDownFlags, We've successfully negotiated aclosing_signed
dance. At this point, theChannelManager
is about to drop us, but we store this anyway.Closed
- CloseFlags, This channel is closed.
The channel data structure
channel_id
- Hash256, The channel IDis_public
- bool, Whether the channel is publicchannel_outpoint
-Option<OutPoint>
, The outpoint of the channelpeer_id
- PeerId, The peer ID of the channelfunding_udt_type_script
-Option<Script>
, The UDT type script of the channelstate
- ChannelState, The state of the channellocal_balance
- u128, The local balance of the channeloffered_tlc_balance
- u128, The offered balance of the channelremote_balance
- u128, The remote balance of the channelreceived_tlc_balance
- u128, The received balance of the channelcreated_at
- u64, The time the channel was created at, in milliseconds from UNIX epoch
The reason for removing a TLC
RemoveTlcFulfill
- , The reason for removing the TLC is that it was fulfilledRemoveTlcFail
- , The reason for removing the TLC is that it failed
The UDT script which is used to identify the UDT configuration for a Fiber Node
code_hash
- H256, The code hash of the script.hash_type
- ScriptHashType, The hash type of the script.args
- String, The arguments of the script.
The UDT cell dep which is used to identify the UDT configuration for a Fiber Node
dep_type
- DepType, The type of the cell dep.tx_hash
- H256, The transaction hash of the cell dep.index
- u32, The index of the cell dep.
The UDT argument info which is used to identify the UDT configuration
name
- String, The name of the UDT.script
- UdtScript, The script of the UDT.auto_accept_amount
-Option<u128>
, The minimum amount of the UDT that can be automatically accepted.cell_deps
-Vec<UdtCellDep>
, The cell deps of the UDT.
A list of UDT configuration infos.
- `` -
Vec<UdtArgInfo>
, The list of UDT configuration infos.
The Node information.
alias
- String, The alias of the node.addresses
-Vec<MultiAddr>
, The addresses of the node.node_id
- Pubkey, The node ID.timestamp
- u64, The timestamp of the node.chain_hash
- Hash256, The chain hash of the node.auto_accept_min_ckb_funding_amount
- u64, The minimum CKB funding amount for automatically accepting open channel requests.udt_cfg_infos
- UdtCfgInfos, The UDT configuration infos of the node.
The Channel information.
channel_outpoint
- OutPoint, The outpoint of the channel.funding_tx_block_number
- u64, The block number of the funding transaction.funding_tx_index
- u32, The index of the funding transaction.node1
- Pubkey, The node ID of the first node.node2
- Pubkey, The node ID of the second node.last_updated_timestamp
-Option<u64>
, The last updated timestamp of the channel, milliseconds since UNIX epoch.created_timestamp
- u64, The created timestamp of the channel, milliseconds since UNIX epoch.node1_to_node2_fee_rate
-Option<u64>
, The fee rate from node 1 to node 2.node2_to_node1_fee_rate
-Option<u64>
, The fee rate from node 2 to node 1.capacity
- u128, The capacity of the channel.chain_hash
- Hash256, The chain hash of the channel.udt_type_script
-Option<Script>
, The UDT type script of the channel.