TITLE: Send Payment Request using cURL DESCRIPTION: Initiates a payment from nodeA to node2 using a previously generated invoice string. The invoice contains all necessary information to route the payment through the channel network. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_23 LANGUAGE: bash CODE: ``` curl -s --location 'http://127.0.0.1:8227' --header 'Content-Type: application/json' --data '{ "id": 6, "jsonrpc": "2.0", "method": "send_payment", "params": [ { "invoice": "fibt1000000001px88ja42xcmczxzat8lhtuq9f29ga8x244qk737nl4r7lq8aw7y7puhjn6jp50xsd2c6ndfxkmn5wnl4z8clk7fej9trwx0gjlmtvnj2wqwlvcu0eekzqvtehlc42t8lpstmgc7ntskh5ef36f8hgvck8c9pescktlx05fpuaceews94kvyrvgf87gvd9wnmh86puzyz2vp6h6jppt8lsq5u8tc87y6szha9587f90dmlmwt5mtetxz9ekukxu6x7s2fyuuy2re0etzzksqnt8rtr5925qypz2224j5xf56nlscnmtvcvywdxg40hsy5w5xt40d5cdest3kvhqswfftfc3qqs7plhlk7m5n9hyzqws9qlxw2huurg7l6c4q9evyg7fljcl3cqh3h3ecpg3fue3cq4slpxapvc2uye6jl77sfcflc8jf8fvr4qwly9wxuyehqf573hu454qy92wqke0hdgrvm7y83sgspn4a29h69s7ucp4cedle" } ] }' ``` LANGUAGE: json CODE: ``` {"jsonrpc":"2.0","result":{"payment_hash":"0x6a356ad088b704a9c53728029bd968e894daf5adab1da838bf06f6755239b005","status":"Created","created_at":"0x1958e7b66b5","last_updated_at":"0x1958e7b66b5","failed_error":null,"fee":"0x186a0"},"id":6} ``` ---------------------------------------- TITLE: Sending Payment via Nervos Fiber RPC - Bash DESCRIPTION: This snippet demonstrates how to initiate a payment on a Nervos Fiber node using a curl command to send an RPC request. It requires a running Fiber node accessible at http://127.0.0.1:8227 and a valid payment invoice. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_16 LANGUAGE: bash CODE: ``` curl -s --location 'http://127.0.0.1:8227' --header 'Content-Type: application/json' --data '{ "id": 6, "jsonrpc": "2.0", "method": "send_payment", "params": [ { "invoice": "fibt1000000001peseucdphcxgfw0pnm6vk3uftyc36dakyjchs0p0unk9gaug0h36uhafww9pvy38gcesad084rx48xgx9xts49yp9fn87yfchld3l3qu5n0pfzvvy8c9g7dksrcxyrtk3hymspezmvtx4vg5v6uvt6tyxmq5uhrfejpk0j6wue9ef2pa8mzmrgqaz3wucutujtjcmq2x8f36faxuctg62ny73mhaj7rpwqe0ns0wp5wr4tku7qcl9r4a3swluvd2jqqwmsl7wsz4cwvhhe7p8tr7hz5qkqwr3r38hukckqzjtmntd8zrz0ywux4u8df005hl76thzsp9hz7dyefzk4mqhx4x9el98zjzmhcveqpfeur79" } ] }' ``` ---------------------------------------- TITLE: Sending Shutdown Channel RPC Request - Shell DESCRIPTION: This `curl` command sends an RPC request to a local Fiber node (http://127.0.0.0:8227) to shut down a specific channel. It includes the channel ID, the script to use for closing (with code hash, hash type, and args), and a fee rate for the closing transaction. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_17 LANGUAGE: Shell CODE: ``` curl -s --location 'http://127.0.0.1:8227' --header 'Content-Type: application/json' --data '{ "id": 9, "jsonrpc": "2.0", "method": "shutdown_channel", "params": [ { "channel_id": "0x26ce85d57fb4a1a826cbf4862358862317a83b775090625550d8be12c6ce9569", "close_script": { "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", "hash_type": "type", "args": "0xcc015401df73a3287d8b2b19f0cc23572ac8b14d" }, "fee_rate": "0x3FC" } ] }' ``` ---------------------------------------- TITLE: Shutdown Channel using cURL DESCRIPTION: Requests to close an open channel with a peer. Requires the channel ID, a script for closing, and a fee rate for the on-chain transaction. This settles the final state of the off-chain channel on the CKB blockchain. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_24 LANGUAGE: bash CODE: ``` curl -s --location 'http://127.0.0.1:8227' --header 'Content-Type: application/json' --data '{ "id": 9, "jsonrpc": "2.0", "method": "shutdown_channel", "params": [ { "channel_id": "0x75dce35923a79086afd0f81b0134ac87619756b6c04a15669ce232aa7db142d8", "close_script": { "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", "hash_type": "type", "args": "0xcc015401df73a3287d8b2b19f0cc23572ac8b14d" }, "fee_rate": "0x3FC" } ] }' ``` LANGUAGE: json CODE: ``` {"jsonrpc":"2.0","result":null,"id":9} ``` ---------------------------------------- TITLE: Generate New Invoice using cURL DESCRIPTION: Requests a node to generate a new invoice for receiving a UDT payment. Specifies the amount, currency, description, expiry, final CLTV delta, a unique payment preimage, hash algorithm, and the UDT type script. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_21 LANGUAGE: bash CODE: ``` curl -s --location 'http://18.163.221.211:8227' --header 'Content-Type: application/json' --data '{ "id": 4, "jsonrpc": "2.0", "method": "new_invoice", "params": [ { "amount": "0x5f5e100", "currency": "Fibt", "description": "test invoice generated by node2", "expiry": "0xe10", "final_cltv": "0x28", "payment_preimage": "0xf7d121b132b4f53bb8301591028b34fccc065f92161bb6e7d41cf6d32ad32a22", "hash_algorithm": "sha256", "udt_type_script": { "code_hash": "0x1142755a044bf2ee358cba9f2da187ce928c91cd4dc8692ded0337efa677d21a", "hash_type": "type", "args": "0x878fcc6f1f08d48e87bb1c3b3d5083f23f8a39c5d5c764f253b55b998526439b" } } ] }' ``` LANGUAGE: json CODE: ``` {"jsonrpc":"2.0","result":{"invoice_address":"fibt1000000001px88ja42xcmczxzat8lhtuq9f29ga8x244qk737nl4r7lq8aw7y7puhjn6jp50xsd2c6ndfxkmn5wnl4z8clk7fej9trwx0gjlmtvnj2wqwlvcu0eekzqvtehlc42t8lpstmgc7ntskh5ef36f8hgvck8c9pescktlx05fpuaceews94kvyrvgf87gvd9wnmh86puzyz2vp6h6jppt8lsq5u8tc87y6szha9587f90dmlmwt5mtetxz9ekukxu6x7s2fyuuy2re0etzzksqnt8rtr5925qypz2224j5xf56nlscnmtvcvywdxg40hsy5w5xt40d5cdest3kvhqswfftfc3qqs7plhlk7m5n9hyzqws9qlxw2huurg7l6c4q9evyg7fljcl3cqh3h3ecpg3fue3cq4slpxapvc2uye6jl77sfcflc8jf8fvr4qwly9wxuyehqf573hu454qy92wqke0hdgrvm7y83sgspn4a29h69s7ucp4cedle","invoice":{"currency":"Fibt","amount":"0x5f5e100","signature":"161b1405170f18161b1e1c090c0a0a010a190409061c1b1a1107130413040f1a0204080504121212150f1b031b171a040417030102191d010a1317090f1f1c120e1909121b0d041b17101f071e1b020d170a151a15121d0d081d12151816171c0d000215190a1801","data":{"timestamp":"0x1958e785913","payment_hash":"0x6a356ad088b704a9c53728029bd968e894daf5adab1da838bf06f6755239b005","attrs":[{"Description":"test invoice generated by node2"},{"ExpiryTime":{"secs":3600,"nanos":0}},{"UdtScript":"0x550000001000000030000000310000001142755a044bf2ee358cba9f2da187ce928c91cd4dc8692ded0337efa677d21a0120000000878fcc6f1f08d48e87bb1c3b3d5083f23f8a39c5d5c764f253b55b998526439b"},{"HashAlgorithm":"sha256"},{"PayeePublicKey":"0291a6576bd5a94bd74b27080a48340875338fff9f6d6361fe6b8db8d0d1912fcc"}]}}},"id":4} ``` ---------------------------------------- TITLE: Generating Invoice via Fiber RPC Bash DESCRIPTION: Calls the new_invoice RPC method on a specific node (node2) to create a payment request (invoice). Specifies the amount (1 CKB), currency, description, expiry, final CLTV delta, payment preimage, and hash algorithm. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_13 LANGUAGE: bash CODE: ``` curl -s --location 'http://18.163.221.211:8227' --header 'Content-Type: application/json' --data '{ "id": 4, "jsonrpc": "2.0", "method": "new_invoice", "params": [ { "amount": "0x5f5e100", "currency": "Fibt", "description": "test invoice generated by node2", "expiry": "0xe10", "final_cltv": "0x28", "payment_preimage": "0xbc03e507befb33cfd5953a2e7046428e69cb8f0ade65c05d3661128aa4b4fff9", "hash_algorithm": "sha256" } ] }' ``` ---------------------------------------- TITLE: Open UDT Channel to Peer using cURL DESCRIPTION: Initiates the process to open a new public UDT channel with a specified peer node. Requires the peer's ID, the funding amount (in hexadecimal), a flag for public visibility, and the UDT's type script details. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_19 LANGUAGE: bash CODE: ``` curl -s --location 'http://127.0.0.1:8227' --header 'Content-Type: application/json' --data '{ "id": 2, "jsonrpc": "2.0", "method": "open_channel", "params": [ { "peer_id": "QmXen3eUHhywmutEzydCsW4hXBoeVmdET2FJvMX69XJ1Eo", "funding_amount": "0x2540be400", "public": true, "funding_udt_type_script": { "code_hash": "0x1142755a044bf2ee358cba9f2da187ce928c91cd4dc8692ded0337efa677d21a", "hash_type": "type", "args": "0x878fcc6f1f08d48e87bb1c3b3d5083f23f8a39c5d5c764f253b55b998526439b" } } ] }' ``` LANGUAGE: json CODE: ``` {"jsonrpc":"2.0","result":{"temporary_channel_id":"0xa3137338377b67ea90c2f2c15b7d60ad27b3e891095f4b093772d7db3aa79344"},"id":2} ``` ---------------------------------------- TITLE: Opening CKB Channel via Fiber RPC Bash DESCRIPTION: Initiates the process of opening a CKB channel with a specified peer (node1), funding it with a certain amount (500 CKB in hex shannons), and setting it as public. Requires node1 to accept the channel based on its configuration. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_7 LANGUAGE: bash CODE: ``` curl -s --location 'http://127.0.0.1:8227' --header 'Content-Type: application/json' --data '{ "id": 2, "jsonrpc": "2.0", "method": "open_channel", "params": [ { "peer_id": "QmXen3eUHhywmutEzydCsW4hXBoeVmdET2FJvMX69J1Eo", "funding_amount": "0xba43b7400", "public": true } ] }' ``` ---------------------------------------- TITLE: Starting Fiber Node (Shell) DESCRIPTION: Launches the FNN executable with necessary configurations. It sets the required environment variable FIBER_SECRET_KEY_PASSWORD for encrypting the wallet key and optionally sets the RUST_LOG level for logging verbosity. It also specifies the configuration file (-c) and the data directory (-d). Replace 'YOUR_PASSWORD' and potentially 'info' with desired values. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/README.md#_snippet_3 LANGUAGE: Shell CODE: ``` FIBER_SECRET_KEY_PASSWORD='YOUR_PASSWORD' RUST_LOG='info' ./fnn -c config.yml -d . ``` ---------------------------------------- TITLE: Starting Fiber Node - Fiber - Bash DESCRIPTION: Sets the `RUST_LOG` environment variable to 'info' for detailed logging, executes the Fiber node binary (`fnn`), specifying the configuration file (`testnet-fnn/nodeA/config.yml`) and data directory (`testnet-fnn/nodeA`). It redirects standard output and error to a log file (`testnet-fnn/nodeA/a.log`) and runs the command in the background. Requires the `fnn` binary, config file, and data directory to be prepared. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_4 LANGUAGE: bash CODE: ``` RUST_LOG=info ./fnn -c testnet-fnn/nodeA/config.yml -d testnet-fnn/nodeA > testnet-fnn/nodeA/a.log 2>&1 & ``` ---------------------------------------- TITLE: Downloading Fiber Node Binary - Fiber - Bash DESCRIPTION: Creates a temporary directory, downloads the specified version of the Fiber node binary (`fnn`) archive for macOS (Apple silicon) from the GitHub releases page, and extracts the contents of the archive. Requires `wget` and `tar` commands to be available. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_1 LANGUAGE: bash CODE: ``` mkdir tmp && cd tmp wget https://github.com/nervosnetwork/fiber/releases/download/v0.4.0/fnn_v0.4.0-x86_64-darwin-portable.tar.gz tar xzvf fnn_v0.4.0-x86_64-darwin-portable.tar.gz ``` ---------------------------------------- TITLE: Listing Public Testnet Node Addresses - Fiber - Bash DESCRIPTION: Provides the multiaddr strings for two public Fiber testnet nodes. These addresses can be used to connect a local node to the testnet network. Each string includes the IP address, TCP port, and the node's Peer ID. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_0 LANGUAGE: bash CODE: ``` "/ip4/18.162.235.225/tcp/8119/p2p/QmXen3eUHhywmutEzydCsW4hXBoeVmdET2FJvMX69XJ1Eo" "/ip4/18.163.221.211/tcp/8119/p2p/QmbKyzq9qUmymW2Gi8Zq7kKVpPiNA1XUJ6uMvsUC4F3p89" ``` ---------------------------------------- TITLE: Connecting Peer Node via Fiber RPC Bash DESCRIPTION: Establishes a network connection between the local Fiber node (nodeA) and a specified remote public node (node1) using the connect_peer RPC method. It sends a JSON-RPC request via curl to the local node's RPC endpoint. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_5 LANGUAGE: bash CODE: ``` curl -s --location 'http://127.0.0.1:8227' --header 'Content-Type: application/json' --data '{ "id": 1, "jsonrpc": "2.0", "method": "connect_peer", "params": [ { "address": "/ip4/18.162.235.225/tcp/8119/p2p/QmXen3eUHhywmutEzydCsW4hXBoeVmdET2FJvMX69XJ1Eo" } ] }' ``` ---------------------------------------- TITLE: Example custom_records Parameter JSON DESCRIPTION: This JSON snippet illustrates the required structure for the `custom_records` parameter used in the `send_payment` RPC method. It shows a map where keys are hexadecimal representations of `u32` record types and values are hexadecimal representations of `Vec` serialized data. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/src/rpc/README.md#_snippet_0 LANGUAGE: json CODE: ``` { "0x1": "0x01020304", "0x2": "0x05060708", "0x3": "0x090a0b0c", "0x4": "0x0d0e0f10010d090a0b0c" } ``` ---------------------------------------- TITLE: Example Payment Custom Records JSON DESCRIPTION: Illustrates the expected JSON format for the `custom_records` field within payment data. It shows how arbitrary key-value pairs are represented using hex-encoded `u32` keys and hex-encoded `Vec` values. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/src/rpc/README.md#_snippet_2 LANGUAGE: json CODE: ``` "custom_records": { "0x1": "0x01020304", "0x2": "0x05060708", "0x3": "0x090a0b0c", "0x4": "0x0d0e0f10010d090a0b0c" } ``` ---------------------------------------- TITLE: Querying Channels via Fiber RPC Bash DESCRIPTION: Queries the status and details of channels established with a specific peer (node1) using the list_channels RPC method. Useful for checking the state, balances, and other properties of existing channels. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_9 LANGUAGE: bash CODE: ``` curl -s --location 'http://127.0.0.1:8227' --header 'Content-Type: application/json' --data '{ "id": 3, "jsonrpc": "2.0", "method": "list_channels", "params": [ { "peer_id": "QmXen3eUHhywmutEzydCsW4hXBoeVmdET2FJvMX69J1Eo" } ] }' ``` ---------------------------------------- TITLE: Query Channels with Peer using cURL DESCRIPTION: Retrieves a list of channels established with a specific peer ID. Useful for checking channel status, balances, and other details after opening or before payment operations. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_20 LANGUAGE: bash CODE: ``` curl -s --location 'http://127.0.0.1:8227' --header 'Content-Type: application/json' --data '{ "id": 3, "jsonrpc": "2.0", "method": "list_channels", "params": [ { "peer_id": "QmXen3eUHhywmutEzydCsW4hXBoeVmdET2FJvMX69XJ1Eo" } ] }' ``` LANGUAGE: json CODE: ``` {"jsonrpc":"2.0","result":{"channels":[{"channel_id":"0x75dce35923a79086afd0f81b0134ac87619756b6c04a15669ce232aa7db142d8","is_public":true,"channel_outpoint":"0x8e133056792766e1fd34e870fb33990b58c4ebb9615526b38dacdf3686cf6d3f00000000","peer_id":"QmXen3eUHhywmutEzydCsW4hXBoeVmdET2FJvMX69XJ1Eo","funding_udt_type_script":{"code_hash":"0x1142755a044bf2ee358cba9f2da187ce928c91cd4dc8692ded0337efa677d21a","hash_type":"type","args":"0x878fcc6f1f08d48e87bb1c3b3d5083f23f8a39c5d5c764f253b55b998526439b"},"state":{"state_name":"CHANNEL_READY","state_flags":[]},"local_balance":"0x2540be400","offered_tlc_balance":"0x0","remote_balance":"0x0","received_tlc_balance":"0x0","latest_commitment_transaction_hash":"0x2b0b36c5db14778484358a4641bfe00a4f351660c280255ef8e8538898e399d0","created_at":"0x1958977b7be","enabled":true,"tlc_expiry_delta":"0x5265c00","tlc_fee_proportional_millionths":"0x3e8"}]},"id":3} ``` ---------------------------------------- TITLE: Query Node1 Channels with Node2 Balances using cURL DESCRIPTION: Queries channels between node1 and node2 to inspect their balances, specifically looking for UDT channels (where `funding_udt_type_script` is not null). This helps observe balance changes after payments. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_22 LANGUAGE: bash CODE: ``` curl -s --location 'http://18.162.235.225:8227' --header 'Content-Type: application/json' --data '{ "id": 5, "jsonrpc": "2.0", "method": "list_channels", "params": [ { "peer_id": "QmbKyzq9qUmymW2Gi8Zq7kKVpPiNA1XUJ6uMvsUC4F3p89" } ] }' ``` LANGUAGE: json CODE: ``` {"local_balance":"0x172a2c63bb","remote_balance":"0x1e4a8445"} {"local_balance":"0x1748630df7","remote_balance":"0x13da09"} {"local_balance":"0xa38b9d","remote_balance":"0x1747d35c63"} {"local_balance":"0xc505f","remote_balance":"0x17486a97a1"} ``` ---------------------------------------- TITLE: Querying Node1 Channels via Fiber RPC Bash DESCRIPTION: Queries the status and details of channels specifically between node1 and node2 from node1's perspective using the list_channels RPC method. Useful for verifying the state and balances of the channel on node1's side before attempting a payment. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_15 LANGUAGE: bash CODE: ``` curl -s --location 'http://18.162.235.225:8227' --header 'Content-Type: application/json' --data '{ "id": 5, "jsonrpc": "2.0", "method": "list_channels", "params": [ { "peer_id": "QmbKyzq9qUmymW2Gi8Zq7kKVpPiNA1XUJ6uMvsUC4F3p89" } ] }' ``` ---------------------------------------- TITLE: Importing CKB Wallet Key (Shell) DESCRIPTION: Sets up a directory for CKB keys, exports a private key using the ckb-cli tool, extracts only the private key part from the exported file, saves it to 'ckb/key', and then removes the temporary export file. This provides the private key required by the FNN's built-in wallet for signing funding transactions. Replace with your actual lock argument. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/README.md#_snippet_2 LANGUAGE: Shell CODE: ``` mkdir ckb ckb-cli account export --lock-arg --extended-privkey-path ./ckb/exported-key // ckb-cli exports master private key and chain code, FNN only needs the private key part head -n 1 ./ckb/exported-key > ./ckb/key // the exported key file can be deleted after the private key is extracted rm ./ckb/exported-key ``` ---------------------------------------- TITLE: Starting Fiber/CKB Nodes - Shell DESCRIPTION: Executes the script to start the development node setup for Fiber (FNN) and CKB. It automatically initializes the dev chain if it hasn't been set up previously, providing a ready environment for development and testing. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/dev/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` ./tests/nodes/start.sh ``` ---------------------------------------- TITLE: Generating Random Payment Preimage Bash DESCRIPTION: Uses the openssl command-line tool to generate a cryptographically secure, random 32-byte hexadecimal number. This is typically used as the payment preimage for creating invoices. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_11 LANGUAGE: bash CODE: ``` # Generate a 32-byte random number and represent it in hexadecimal payment_preimage="0x$(openssl rand -hex 32)" echo $payment_preimage ``` ---------------------------------------- TITLE: (Re)Initializing Development Chain - Shell DESCRIPTION: Runs the script to initialize or re-initialize the CKB development chain. This process can include transferring default balances from a designated account and deploying necessary contracts. The optional `-f` parameter can be used to forcefully clean all old state before initialization, useful for resetting the dev chain to a pristine state. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/dev/README.md#_snippet_2 LANGUAGE: Shell CODE: ``` ./tests/deploy/init-dev-chain.sh [-f] ``` ---------------------------------------- TITLE: Starting Fiber/CKB Nodes Cleanly - Shell DESCRIPTION: Executes the script to start the development node setup, explicitly setting the `REMOVE_OLD_STATE` environment variable to 'y'. This command removes any old state before starting, which is useful for development when database schemas or other states might change and require a clean environment. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/dev/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` REMOVE_OLD_STATE=y ./tests/nodes/start.sh ``` ---------------------------------------- TITLE: Removing Node Storage (Shell) DESCRIPTION: Deletes the entire storage directory used by the Fiber Network Node. This action is typically performed during an incompatible upgrade when preserving channel state is not possible or desired. **Warning**: This will result in the loss of all channel data and associated funds in those channels. Ensure you have closed channels or backed up data if needed. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/README.md#_snippet_4 LANGUAGE: Shell CODE: ``` rm -rf /folder-to/my-fnn/fiber/store ``` ---------------------------------------- TITLE: Building Fiber Node Binary (Shell) DESCRIPTION: Compiles the Fiber Network Node project using Cargo in release mode. This command is used to build an optimized executable binary from the source code. It requires Rust and Cargo to be installed on the system. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` cargo build --release ``` ---------------------------------------- TITLE: Setting Up Node Directory (Shell) DESCRIPTION: Creates a dedicated directory for the FNN instance, copies the compiled binary and testnet configuration file into it, and changes the current directory to the newly created one. This prepares the workspace for running the node. Ensure the paths for the binary and config file are correct. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` mkdir /folder-to/my-fnn // if you are using the released binary, replace target/release/fnn with the path of released binary cp target/release/fnn /folder-to/my-fnn cp config/testnet/config.yml /folder-to/my-fnn cd /folder-to/my-fnn ``` ---------------------------------------- TITLE: Copying Node Configuration - Fiber - Bash DESCRIPTION: Copies the testnet configuration file (`config.yml`) from its source location (`config/testnet/`) to the designated directory for the local Fiber node (`testnet-fnn/nodeA`). This prepares the node directory with the necessary configuration for startup. Assumes the source config file exists. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_3 LANGUAGE: bash CODE: ``` cp config/testnet/config.yml testnet-fnn/nodeA ``` ---------------------------------------- TITLE: Fiber RPC connect_peer Success Response JSON DESCRIPTION: Example JSON response indicating a successful network connection request initiated by the connect_peer RPC call. A 'result' of null signifies success. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_6 LANGUAGE: json CODE: ``` {"jsonrpc":"2.0","result":null,"id":1} ``` ---------------------------------------- TITLE: Fiber RPC open_channel Success Response JSON DESCRIPTION: Example JSON response indicating the successful initiation of an open_channel request. The 'result' contains a temporary channel ID that identifies this specific channel proposal. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_8 LANGUAGE: json CODE: ``` {"jsonrpc":"2.0","result":{"temporary_channel_id":"0x30089ec4c8ce1e1d4930220c2bff856eec7ab44550e15b76d62489fd42eaafe8"},"id":2} ``` ---------------------------------------- TITLE: Fiber RPC new_invoice Success Response JSON DESCRIPTION: Example JSON response confirming the successful creation of a new invoice. Contains the invoice address string and detailed invoice data including amount, currency, timestamp, payment hash, and payee public key. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_14 LANGUAGE: json CODE: ``` {"jsonrpc":"2.0","result":{"invoice_address":"fibt1000000001peseucdphcxgfw0pnm6vk3uftyc36dakyjchs0p0unk9gaug0h36uhafww9pvy38gcesad084rx48xgx9xts49yp9fn87yfchld3l3qu5n0pfzvvy8c9g7dksrcxyrtk3hymspezmvtx4vg5v6uvt6tyxmq5uhrfejpk0j6wue9ef2pa8mzmrgqaz3wucutujtjcmq2x8f36faxuctg62ny73mhaj7rpwqe0ns0wp5wr4tku7qcl9r4a3swluvd2jqqwmsl7wsz4cwvhhe7p8tr7hz5qkqwr3r38hukckqzjtmntd8zrz0ywux4u8df005hl76thzsp9hz7dyefzk4mqhx4x9el98zjzmhcveqpfeur79","invoice":{"currency":"Fibt","amount":"0x5f5e100","signature":"0e1b101f1e0e100215180e0c1717191e01070b031e1702140016000e0311031107171c1618160002120b1b130b0d070203020f040e1c06151c070d090f0f14171f1e1a0b170210010517021e0d0419090216151b001706150605191f05070212021b17180c190001","data":{"timestamp":"0x1958944fa64","payment_hash":"0xafb604f74c28009732ed4c82983cf1efaddf62ee36442f360fb4a8c79b845432","attrs":[{"Description":"test invoice generated by node2"},{"ExpiryTime":{"secs":3600,"nanos":0}},{"HashAlgorithm":"sha256"},{"PayeePublicKey":"0291a6576bd5a94bd74b27080a48340875338fff9f6d6361fe6b8db8d0d1912fcc"}]}}},"id":4} ``` ---------------------------------------- TITLE: Fiber RPC list_channels Response JSON DESCRIPTION: Example JSON response listing the details of channels associated with the queried peer. Includes channel state (e.g., CHANNEL_READY), IDs, balances (local_balance, remote_balance), and other properties. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_10 LANGUAGE: json CODE: ``` {"jsonrpc":"2.0","result":{"channels":[{"channel_id":"0x26ce85d57fb4a1a826cbf4862358862317a83b775090625550d8be12c6ce9569","is_public":true,"channel_outpoint":"0x9bb2a8a4bebaf793a235ba2ec87051ae0018b58736b6741df74009ca8101cb8d00000000","peer_id":"QmXen3eUHhywmutEzydCsW4hXBoeVmdET2FJvMX69J1Eo","funding_udt_type_script":null,"state":{"state_name":"CHANNEL_READY","state_flags":[]},"local_balance":"0xa32aef600","offered_tlc_balance":"0x0","remote_balance":"0x460913c00","received_tlc_balance":"0x0","latest_commitment_transaction_hash":"0x18ef541a5a195c0ea4715a7783964b3c4be8fba6bd25542e626f91ef1673e3e4","created_at":"0x195892d237f","enabled":true,"tlc_expiry_delta":"0x5265c00","tlc_fee_proportional_millionths":"0x3e8"}]},"id":3} ``` ---------------------------------------- TITLE: Successful RPC Response - JSON DESCRIPTION: This JSON object represents the standard successful response format for an RPC call. The `jsonrpc` field indicates the version, `result` being null signifies that the operation completed successfully without returning data, and `id` matches the request ID. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_18 LANGUAGE: JSON CODE: ``` {"jsonrpc":"2.0","result":null,"id":9} ``` ---------------------------------------- TITLE: Starting Fiber Test Nodes (Shell) DESCRIPTION: This command executes a shell script to start the network nodes required for running the end-to-end fiber channel tests. It sets up the necessary environment for the test scenario described. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/tests/bruno/e2e/open-use-close-a-channel/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` ./tests/nodes/start.sh ``` ---------------------------------------- TITLE: Running API Tests with Bruno - Shell DESCRIPTION: Changes the current directory to the Bruno test suite location (`tests/bruno`) and then executes the Bruno CLI via `npm exec`. This command runs a specific end-to-end test collection (`e2e/open-use-close-a-channel`) against the configured test environment, useful for verifying core functionality of the running dev chain setup. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/dev/README.md#_snippet_3 LANGUAGE: Shell CODE: ``` cd tests/bruno npm exec -- @usebruno/cli run e2e/open-use-close-a-channel -r --env test ``` ---------------------------------------- TITLE: Running Cross-Chain Hub E2E Tests (Shell) DESCRIPTION: This command executes the end-to-end tests for the cross-chain hub using the Bruno CLI tool. It specifies the test collection path and the 'test' environment configuration. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/tests/bruno/e2e/cross-chain-hub/README.md#_snippet_0 LANGUAGE: shell CODE: ``` npm exec -- @usebruno/cli run e2e/cross-chain-hub -r --env test ``` ---------------------------------------- TITLE: Running Bruno E2E Channel Test (Shell) DESCRIPTION: This command sequence changes the directory to the Bruno test collection location and then executes the specified Bruno collection using the Bruno CLI. It runs the end-to-end test scenario for opening, using, and closing a fiber channel in the 'test' environment. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/tests/bruno/e2e/open-use-close-a-channel/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` cd tests/bruno npm exec -- @usebruno/cli run e2e/open-use-close-a-channel -r --env test ``` ---------------------------------------- TITLE: Defining AddTlc Message - Molecule Schema DESCRIPTION: Defines the AddTlc message structure used to initiate a payment operation or forward a payment request via a Time Locked Contract (TLC). It includes channel ID, unique TLC ID, amount, payment hash, and expiry timestamp. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_12 LANGUAGE: Molecule Schema CODE: ``` table AddTlc { channel_id: Byte32, tlc_id: Uint64, amount: Uint128, payment_hash: Byte32, expiry: Uint64, } ``` ---------------------------------------- TITLE: ChannelReady Message Structure (Molecule) DESCRIPTION: Defines the structure of the ChannelReady message, sent after the funding transaction is signed and broadcast. It signals that the channel is ready for use and contains only the channel ID. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_4 LANGUAGE: Molecule CODE: ``` table ChannelReady { channel_id: Byte32, } ``` ---------------------------------------- TITLE: OpenChannel Message Structure (Molecule) DESCRIPTION: Defines the structure of the OpenChannel message, sent by the initiator to request channel establishment. It contains parameters like chain hash, channel ID, funding details, TLC limits, public keys, and channel flags. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_0 LANGUAGE: Molecule CODE: ``` table OpenChannel { chain_hash: Byte32, channel_id: Byte32, funding_type_script: ScriptOpt, funding_amount: Uint128, funding_fee_rate: Uint64, commitment_fee_rate: Uint64, max_tlc_value_in_flight: Uint128, max_tlc_number_in_flight: Uint64, min_tlc_value: Uint128, to_self_delay: Uint64, funding_pubkey: Byte33, tlc_basepoint: Byte33, first_per_commitment_point: Byte33, second_per_commitment_point: Byte33, next_local_nonce: Byte66, channel_flags: Byte, } ``` ---------------------------------------- TITLE: Defining RemoveTlc Messages - Molecule Schema DESCRIPTION: Defines the messages and structures used by the AddTlc recipient to remove a TLC. RemoveTlc specifies the channel and TLC ID and reason (Fulfill or Fail). RemoveTlcReason is a union covering fulfillment or failure states. RemoveTlcFulfill contains the payment preimage, while RemoveTlcFail contains an error code. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_14 LANGUAGE: Molecule Schema CODE: ``` table RemoveTlc { channel_id: Byte32, tlc_id: Uint64, reason: RemoveTlcReason } union RemoveTlcReason { RemoveTlcFulfill, RemoveTlcFail, } struct RemoveTlcFulfill { payment_preimage: Byte32, } struct RemoveTlcFail { error_code: Uint32, } ``` ---------------------------------------- TITLE: Defining TxAckRBF Message - Molecule Schema DESCRIPTION: Defines the TxAckRBF message structure used by the channel responder to agree to an RBF operation initiated by TxInitRBF. It only contains the channel identifier. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_9 LANGUAGE: Molecule Schema CODE: ``` table TxAckRBF { channel_id: Byte32, } ``` ---------------------------------------- TITLE: AcceptChannel Message Structure (Molecule) DESCRIPTION: Defines the structure of the AcceptChannel message, sent by the receiver to accept a channel establishment request. It mirrors many fields from OpenChannel and includes the receiver's funding contribution, TLC limits, and public keys. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_1 LANGUAGE: Molecule CODE: ``` table AcceptChannel { channel_id: Byte32, funding_amount: Uint128, max_tlc_value_in_flight: Uint128, max_tlc_number_in_flight: Uint64, min_tlc_value: Uint128, to_self_delay: Uint64, funding_pubkey: Byte33, tlc_basepoint: Byte33, payment_basepoint: Byte33, delayed_payment_basepoint: Byte33, first_per_commitment_point: Byte33, second_per_commitment_point: Byte33, next_local_nonce: Byte66, } ``` ---------------------------------------- TITLE: Example Payment Preimage Output Bash DESCRIPTION: Example output from the openssl command, showing a randomly generated 32-byte (64 hex characters) number prefixed with '0x'. This value is used when creating a new invoice. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/testnet-nodes.md#_snippet_12 LANGUAGE: bash CODE: ``` 0xbc03e507befb33cfd5953a2e7046428e69cb8f0ade65c05d3661128aa4b4fff9 ``` ---------------------------------------- TITLE: Defining TxInitRBF Message - Molecule Schema DESCRIPTION: Defines the TxInitRBF message structure used by the channel initiator to request an RBF (Replace-By-Fee) operation for the funding transaction. It specifies the channel identifier and the desired new fee rate. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_8 LANGUAGE: Molecule Schema CODE: ``` table TxInitRBF { channel_id: Byte32, fee_rate: Uint64, } ``` ---------------------------------------- TITLE: Defining TxComplete Message - Molecule Schema DESCRIPTION: Defines the TxComplete message structure indicating the successful completion of the transaction construction process. It contains the channel identifier. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_6 LANGUAGE: Molecule Schema CODE: ``` table TxComplete { channel_id: Byte32, } ``` ---------------------------------------- TITLE: Defining TxUpdate Message - Molecule Schema DESCRIPTION: Defines the TxUpdate message structure used by the channel initiator to begin the transaction construction protocol. It includes the channel identifier and the transaction data. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_5 LANGUAGE: Molecule Schema CODE: ``` table TxUpdate { channel_id: Byte32, tx: Transaction, } ``` ---------------------------------------- TITLE: Defining ClosingSigned Message - Molecule Schema DESCRIPTION: Defines the ClosingSigned message structure sent after completing pending TLCs to sign the close transaction. It includes the channel identifier and a partial signature for the transaction. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_11 LANGUAGE: Molecule Schema CODE: ``` table ClosingSigned { channel_id: Byte32, partial_signature: Byte32, } ``` ---------------------------------------- TITLE: CommitmentSigned Message Structure (Molecule) DESCRIPTION: Defines the structure of the CommitmentSigned message, exchanged after commitment transaction signing. It contains the channel ID, a partial signature for the 2-2 Schnorr multisig, and the next local nonce for future partial signatures. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_2 LANGUAGE: Molecule CODE: ``` table CommitmentSigned { channel_id: Byte32, partial_signature: Byte32, next_local_nonce: Byte66, } ``` ---------------------------------------- TITLE: Defining RevokeAndAck Message - Molecule Schema DESCRIPTION: Defines the RevokeAndAck message structure used to reveal the previous commitment transaction secret and acknowledge a new state after receiving and verifying a CommitmentSigned message. It contains the channel ID, previous secret, next commitment point, and next local nonce. SOURCE: https://github.com/nervosnetwork/fiber/blob/develop/docs/specs/p2p-message.md#_snippet_13 LANGUAGE: Molecule Schema CODE: ``` table RevokeAndAck { channel_id: Byte32, per_commitment_secret: Byte32, next_per_commitment_point: Byte33, next_local_nonce: Byte66, } ```