@confio/relayer

中文文档
0.12.0发布于 2024/03/08MITTypeScriptCommonJS近 30 天下载 6340

IBC Relayer in TypeScript

原始使用文档
文档目录18 节
  1. Requirements
  2. Important Note
  3. Installation
  4. NPM
  5. Usage
  6. ibc-setup
  7. ibc-relayer
  8. Quick start
  9. Configure and start the relayer
  10. Send tokens between chains
  11. Configuration overview
  12. Monitoring
  13. Local setup
  14. Development
  15. Integration Tests
  16. Chain Requirements
  17. Full Node Requirements
  18. Web App

Relayer

npm version

TypeScript implementation of an IBC Relayer.

To get a good overview of what it can do, please check our feature matrix

You can also read our specification page, which explains how the relayer works, but the Quick Start probably gives a better intro.

This repo is mainly used as a node binary to perform IBC relaying. However, all logic is available in the library, which can be run equally well in the browser or in Node. You can see an example of embedding the relayer in a webapp below.

Requirements

  • Node.js 18 or later
  • RPC addresses of 2 full nodes on compatible, IBC-enabled chains
  • See Chain Requirements below for details of what chains are supported

Important Note

Versions until v0.1.6 support Cosmos SDK v0.41.1+. From v0.2.0 on we require Tendermint v0.34.9+ (which is used in SDK v0.42.4+). If you are connecting to a v0.41 chain, please use the v0.1.x relayer.

With v0.2.0 we add support for relaying packets in BeginBlock and EndBlock. However, this requires an extra rpc endpoint in Tendermint that is not available in v0.41.1. We therefore increase the minimum compatible version of the SDK.

Installation

NPM

Install the latest release.

npm i -g @confio/relayer

Alternatively, install from the main branch.

npm i -g @confio/relayer@main

NOTE: We do a manual release after completing a predefined milestone or when it feels right. No release schedule is in place yet. To utilize the latest changes, use the main tag during the installation.

Usage

After installation, ibc-setup and ibc-relayer executables are available.

ibc-setup

Collection of commands to quickly setup a relayer and query IBC/chain data.

ibc-relayer

Reads the configuration and starts relaying packets.

Quick start

Configure and start the relayer

  1. Init the configuration

    ibc-setup init --src malaga --dest uni
    
    • creates relayer's home directory at ~/.ibc-setup
    • creates app.yaml inside relayer's home with src, dest and newly generated mnemonic
    • pulls default registry.yaml to relayer's home
    • funds addresses on malaga so relayer can pay the fee while relaying packets

    NOTE: Both testnets are running in the public. You do not need to start any blockchain locally to complete the quick start guide.

    NOTE: Run ibc-setup balances to see the amount of tokens on each address.

  2. Get testnet tokens for uni

    • Find your relayer address on uni via: ibc-setup keys list | grep uni
    • Join Juno discord with this invite link
    • Go to the faucet channel
    • Request tokens at this address in the above channel: $request iaa1fxmqew9dgg44jdf3l34zwa8rx7tcf42wz8ehjk
    • Check you have tokens on malaga and uni via ibc-setup balances

    See original instructions

  3. Create ics20 channel

    ibc-setup ics20 -v
    
    • creates a new connection on source and desination chains
    • saves connection ids to app.yaml file
    • creates a new channel
  4. Start the relayer in the verbose mode and 10s frequency polling

    ibc-relayer start -v --poll 15
    

Send tokens between chains

  1. Make sure wasmd binary is installed on your system

    • you must be running Linux or OSX on amd64 (not arm64/Mac M1)
    • install Go 1.17+ and ensure that $PATH includes Go binaries (you may need to restart your terminal session)
    • clone and install wasmd:
      git clone https://github.com/CosmWasm/wasmd.git
      cd wasmd
      git checkout v0.27.0
      make install
      
  2. Make sure juno binary is installed on your system

    • you must be running Linux or OSX on amd64
    • install Go 1.17+ and ensure that $PATH includes Go binaries (you may need to restart your terminal session)
    • clone and install juno:
      git clone https://github.com/CosmosContracts/juno
      cd juno
      git checkout v6.0.0
      make install
      
  3. Create a new account and fund it

    wasmd keys add sender
    JSON=$(jq -n --arg addr $(wasmd keys show -a sender) '{"denom":"usponge","address":$addr}')
    curl -X POST --header "Content-Type: application/json" --data "$JSON" https://faucet.malaga.cosmwasm.com/credit
    
  4. Create a valid IRISnet address to send tokens to

    junod keys add receiver
    

    Get testnet tokens if you want to send tokens to malaga.

  5. Send tokens

    wasmd tx ibc-transfer transfer transfer <channel-id> $(junod keys show -a receiver) 200usponge --from $(wasmd keys show -a sender) --node http://rpc.malaga.cosmwasm.com:80 --chain-id malaga-1 --fees 2000usponge --packet-timeout-height 0-0
    
    • replace <channel-id> with the channel id obtained while configuring the relayer (2nd point)
    • if you cleared out the terminal, query the channel
      ibc-setup channels --chain malaga
      
  6. Observe the relayer output

Configuration overview

The relayer configuration is stored under relayer's home directory. By default, it's located at $HOME/.ibc-setup, however, can be customized with home option, e.g.:

# initialize the configuration at /home/user/relayer_custom_home
ibc-setup init --home /home/user/relayer_custom_home

# read the configuration from /home/user/relayer_custom_home
ibc-relayer start --home /home/user/relayer_custom_home

There are 3 files that live in the relayer's home.

  • registry.yaml (required)

    Contains a list of available chains with corresponding information. The chains from the registry can be referenced by ibc-setup binary or within the app.yaml file. View an example of registry.yaml file.

  • app.yaml (optional)

    Holds the relayer-specific options such as source or destination chains. These options can be overridden with CLI flags or environment variables.

  • last-queried-heights.json (optional)

    Stores last queried heights for better performance on relayer startup. It's constantly overwritten with new heights when relayer is running. Simply delete this file to scan the events since forever.

Learn more about configuration.

Monitoring

The relayer collects various metrics that a Prometheus instance can consume.

To enable metrics collection, pass the --enable-metrics flag when starting the relayer:

ibc-relayer start --enable-metrics

NOTE: Metrics can also be enabled via an environment variable RELAYER_ENABLE_METRICS=true, or with an enableMetrics: true entry in the app.yaml file, as explained in the config specification.

The GET /metrics endpoint will be exposed by default on port 8080, which you can override with --metrics-port flag, RELAYER_METRICS_PORT env variable, or metricsPort entry in app.yaml.

Local setup

Prometheus

  1. Start the relayer with metrics enabled
  2. Spin up the Prometheus instance:
    docker run -it -v $(pwd):/prometheus -p9090:9090 prom/prometheus --config.file=demo/prometheus.yaml
    

    NOTE: Ensure that the --config.file=<path> flag points at the existing configuration file. If you wish to use the example config, just run the command above in the root of this repository. Otherwise, you must adjust the volume (-v) and config file path to your setup.

  3. Open the Prometheus dashboard in a browser at http://localhost:9090

Grafana

  1. Spin up the Grafana instance:
    docker run -d --name=grafana -p 3000:3000 grafana/grafana
    
  2. Navigate to http://localhost:3000 and log in (admin/admin)
  3. Create a Prometheus data source

    NOTE: Use http://host.docker.internal:9090 as the server URL and Server as the Access method.

  4. Create a new graph and query data

    NOTE: Useful guides:

Development

Refer to the development page.

Integration Tests

ts-relayer can be used as a library as well as a binary. This allows us to make powerful node scripts, or to easily test CosmWasm contract IBC flows in CI code. You can look at the following two examples on how to do so:

Chain Requirements

The blockchain must be based on Cosmos SDK v0.42.4+. In particular it must have PR 8458 and PR 9081 merged (if you are using a fork) in order for the relayer to work properly. ibc-setup should work on v0.40.0+

The chain must have a large value for staking.params.historical_entries (often set in genesis). The default is "10000" and this should work with "1000", but no relayer will work if it is set to 0.

Full Node Requirements

Ideally you are in control of the node that the relayer connects to. If not, it should be run by a known and trusted party, whom you can check the configuration with. Note that a malicious node could cause the relayer to send invalid packets and waste tokens on gas (but not create invalid state).

The indexer should be enabled (tx_index.indexer = "kv" in config.toml), and all events should be indexed (index-events = [] in app.toml).

The node must support historical queries. --pruning=nothing will definitely work, but will use an enormous amount of disk space. You can also trim it to 3 weeks of data with --pruning=custom --pruning-keep-recent=362880 --pruning-keep-every=0 --pruning-interval=100, which has been tested. It is likely you could reduce pruning-keep-recent to as low as, say, 3600, but that would need testing.

Web App

This repo can also be imported as a library and used in a web app. @clockworkgr has been so nice to share a sample Vue.js app using the relayer. This includes some nice code samples to send a IbcTransfer message with CosmJS as well as setting up and running the relayer.

screenshot

The key import is import { IbcClient, Link } from "@confio/relayer/build";

版本与发布记录

@confio/relayer 共发布 105 个版本,首次发布于 2021/03/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.12.0latest2024/03/082 年前
0.11.32024/02/252 年前
0.11.22023/12/062 年前
0.11.12023/12/052 年前
0.11.02023/11/292 年前
0.10.02023/08/163 年前

其他发布通道:main → 0.0.0-main-3b30964。

关于 @confio/relayer 的常见问题

@confio/relayer 是什么?

IBC Relayer in TypeScript

如何安装 @confio/relayer?

在项目目录运行 npm install @confio/relayer,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 ibc-setup、ibc-relayer,可以用 npx ibc-setup 直接运行。

@confio/relayer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@confio/relayer 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@confio/relayer 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@confio/relayer 可以商用吗?

@confio/relayer 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@confio/relayer 的下载量有多少?

根据 npm 官方下载统计,@confio/relayer 在 2026/10/11 – 2026/11/09 这 30 天内被下载 6,340 次,日均约 211 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@confio/relayer 还在维护吗?

最新版本 0.12.0 发布于 2024/03/08(2 年前);至今共发布 105 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/03/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。