Raiden Network
  • What is Raiden?
  • Installation
    • Quick Start
      • Get MetaMask
      • Get an Infura ID
      • Download and run the Raiden Wizard
      • Handle Limitations
    • Starting Raiden Manually
  • Using Raiden on Mainnet
    • Overview
    • Get Whitelisted Tokens
    • Deposit Tokens to the UDC
    • Open a Channel
    • Make a Payment
    • Deposit Tokens
    • View Channel Status
    • Mediation Fees
  • The Raiden Web Interface
    • Overview
    • Navigate the WebUI
    • Join a Token Network
    • Make a Payment
    • Add More Tokens
    • Settle Payments and Close Channels
  • Using Raiden on testnet
    • Quick Start on Görli Testnet
    • Use Custom Token
      • Get Goerli Testnet ETH (GÖETH)
      • Import Custom Token
      • Compile Imported Token Code
      • Deploy Custom Token
  • Raiden API
    • Introduction
    • Resources
      • Address
      • Version
      • Settings
      • Contracts Information
      • Tokens
      • Channels
      • Payments
      • Connections
      • Pending Transfers
      • Shutdown
      • Testing
    • API Tutorial
      • Create a Token Network
      • Open a Channel
      • Deposit Tokens
      • Make a Payment
      • Withdraw Tokens
      • Settle Payments and Close Channels
  • Other
    • Safe Usage
    • Known Issues
    • Glossary
    • v1.0 Documentation
    • Trademark Attributions
Powered by GitBook
On this page
  • Find suitable partner nodes
  • Open a channel
  • Query the state of a channel

Was this helpful?

  1. Raiden API
  2. API Tutorial

Open a Channel

Channels allow tokens to move between the two connected Raiden nodes. You need at least one channel to make payments in a Token Network.

PreviousCreate a Token NetworkNextDeposit Tokens

Last updated 4 years ago

Was this helpful?

This section will cover the endpoints you would use to:

  1. Find suitable partner nodes

Find suitable partner nodes

To make payments, you need to be connected to the target node either directly, or indirectly by having a channel with a well connected that mediates your payment to the target. If you already know to which node you want to connect, skip ahead to the next section.

The Path Finding Service (PFS) can suggest partners that are highly connected. These nodes will be able to mediate your payments to a large amount of potential targets and are thus a good choice for your first channel(s). Ask the PFS by sending a GET request to its partner suggestion endpoint for the token you want to use.

curl https://pfs.of.your.choice/api/v1/0x9aBa529db3FF2D8409A1da4C9eB148879b046700/suggest_partner

If you don't know which PFS to ask, you can get the URL of the PFS used by your Raiden node from the . The list of suggested partners is sorted with the most recommended ones coming first. If you want to open just a single channel, picking the address of the first partner in the results is a reasonable choice.

[
  {
    "address": "0x99eB1aADa98f3c523BE817f5c45Aa6a81B7c734B",
    "score": 2906634538666422000,
    "centrality": 0.0004132990448199853,
    "uptime": 7032.763746,
    "capacity": 1000000000000000000
  },
  {
    "address": "0x4Fc53fBa9dFb545B66a0524216c982536012186e",
    "score": 2906693668947465000,
    "centrality": 0.0004132990448199853,
    "uptime": 7032.906815,
    "capacity": 1000000000000000000
  }
]

Open a channel

  1. The address of the node you'd like to open the channel with.

  2. The settle timeout period which corresponds to the number of blocks that have to be mined before a closed channel can be settled.

curl -i -X PUT \
http://localhost:5001/api/v1/channels \
-H 'Content-Type: application/json' \
--data-raw '{"partner_address": "0x61C808D82A3Ac53231750daDc13c777b59310bD9", "token_address": "0x9aBa529db3FF2D8409A1da4C9eB148879b046700", "total_deposit": "1337", "settle_timeout": "500"}'

This will create a new channel and a successful request will return you the following response object:

HTTP/1.1 201 CREATED
Content-Type: application/json

{
    "token_network_address": "0x3C158a20b47d9613DDb9409099Be186fC272421a",
    "channel_identifier": "99",
    "partner_address": "0x61C808D82A3Ac53231750daDc13c777b59310bD9",
    "token_address": "0x9aBa529db3FF2D8409A1da4C9eB148879b046700",
    "balance": "1337",
    "total_deposit": "1337",
    "total_withdraw": "0",
    "state": "opened",
    "settle_timeout": "500",
    "reveal_timeout": "50"
}

As you can tell by the response object a channel identifier has been generated. This means that there now is a channel with that identifier inside the token network.

You're now ready to start making payments.

Opening a channel with a partner node is not dependent on whether the partner node holds tokens or not. It will work either way.

Query the state of a channel

  1. The token address as a path parameter.

  2. The address of the partner node as a path parameter.

curl -i \
http://localhost:5001/api/v1/channels/0x9aBa529db3FF2D8409A1da4C9eB148879b046700/0x61C808D82A3Ac53231750daDc13c777b59310bD9

To open a channel a PUT request is made to the endpoint that includes a JSON object containing:

The amount of tokens you want to deposit in the channel. (Remember that it is always possible to later.)

Checking the current state of a channel is as easy as making a query to the endpoint while providing:

This will give you the same response object as when .

deposit more tokens
Make a Payment
opening a channel
Open a Channel
Open a channel
Query the state of a channel
channels
channels
settings endpoint