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.
btc_pay_req
- Bitcoin payment request string
Returns null when the payment request string is valid. Otherwise, returns an error message.
RPC module for channel management.
Attempts to open a channel with a peer.
peer_id
- The peer ID to open a channel withfunding_amount
- The amount of CKB or UDT to fund the channel withpublic
- Whether this is a public channel (will be broadcasted to network, and can be used to forward TLCs), an optional parameter (default value false)funding_udt_type_script
- The type script of the UDT to fund the channel with, an optional parametercommitment_fee_rate
- The fee rate for the commitment transaction, an optional parameterfunding_fee_rate
- The fee rate for the funding transaction, an optional parametertlc_locktime_expiry_delta
- The expiry delta for the TLC locktime, an optional parametertlc_min_value
- The minimum value for a TLC, an optional parametertlc_max_value
- The maximum value for a TLC, an optional parametertlc_fee_proportional_millionths
- The fee proportional millionths for a TLC, an optional parametermax_tlc_value_in_flight
- The maximum value in flight for TLCs, an optional parametermax_num_of_accept_tlcs
- The maximum number of TLCs that can be accepted, an optional parameter
temporary_channel_id
- The temporary channel ID of the channel being opened
Accepts a channel opening request from a peer.
temporary_channel_id
- The temporary channel ID of the channel to acceptfunding_amount
- The amount of CKB or UDT to fund the channel with
channel_id
- The final ID of the channel that was accepted, it's different from the temporary channel ID
Lists all active channels that the node is participating in.
peer_id
- Only list channels with this remote peer ID, an optional parameter
channels
- An array of channel objectschannel_id
- The ID of the channelpeer_id
- The remote peer ID of the channelfunding_udt_type_script
- The type script of the UDT used to fund the channel, may be nullstatus
- The status of the channellocal_balance
- The balance of the channel owned by the local noderemote_balance
- The balance of the channel owned by the remote peeroffered_tlc_balance
- The total balance of currently offered TLCs in the channelreceived_tlc_balance
- The total balance of currently received TLCs in the channelcreated_at
- The timestamp when the channel was created, in milliseconds
Adds a TLC to the channel.
channel_id
- The ID of the channel to add the TLC toamount
- The amount of CKB or UDT to add to the TLCpayment_hash
- The payment hash of the TLCexpiry
- The expiry time of the TLC
tlc_id
- The ID of the TLC that was added
Removes a TLC from the channel.
channel_id
- The ID of the channel to remove the TLC fromtlc_id
- The ID of the TLC to removereason
- The reason for removing the TLC, either a 32-byte hash for preimage fulfillment or an u32 error code for removal
Returns null when the TLC is removed successfully. Otherwise, returns an error message.
Attempts to close the channel mutually.
channel_id
- The ID of the channel to closeclose_script
- The script used to receive the channel balance, only support secp256k1_blake160_sighash_all script for nowfee_rate
- The fee rate for the closing transaction, the fee will be deducted from the closing initiator's channel balance
Returns null when the request is successful. Otherwise, returns an error message.
Sends a payment to a peer.
target_pubkey
(type:Pubkey
): The identifier of the payment target.amount
(type:u128
): The amount of the payment.payment_hash
(type:Hash256
): The hash to use within the payment's HTLC.final_cltv_delta
(type:Option<u64>
): The CLTV delta from the current height that should be used to set the timelock for the final hop.invoice
(type:Option<String>
): The encoded invoice to send to the recipient.timeout
(type:Option<u64>
): The payment timeout in seconds. If the payment is not completed within this time, it will be cancelled.max_fee_amount
(type:Option<u128>
): The maximum fee amounts in shannons that the sender is willing to pay.max_parts
(type:Option<u64>
): Max parts for the payment, only used for multi-part payments.
Note target_pubkey
, amount
, payment_hash
should be consistent with the invoice. If invoice
is provided, the target_pubkey
, amount
, payment_hash
can be omitted.
If invoice
is not provided, the target_pubkey
, amount
must be provided, if payment_hash
is not provided, the payment_hash
will be generated by the node with a random preimage (means the keysend
mode) in payment.
Returns the payment_hash
when the request is successful. Otherwise, returns an error message.
RPC module for invoice management.
Generates a new invoice.
amount
- The amount of CKB or UDT to requestcurrency
- The currency of the amount, either "CKB" or the UDT type scriptdescription
- The description of the invoice, an optional parameterexpiry
- The expiry time of the invoice, an optional parameterpayment_preimage
- The payment preimage of the invoice
Returns the generated invoice string when the request is successful. Otherwise, returns an error message.
Parses an invoice string.
invoice
- The invoice string to parse
invoice
- The parsed invoice objectamount
- The amount of CKB or UDT requestedcurrency
- The currency of the amountdescription
- The description of the invoicepayment_hash
- The payment hash of the invoice
RPC module for peer management.
Attempts to connect to a peer.
address
- The address of the peer to connect to
Returns null when the request is successful. Otherwise, returns an error message.
Attempts to disconnect from a peer.
peer_id
- The peer ID to disconnect from
Returns null when the request is successful. Otherwise, returns an error message.