You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Starport运行多节点区块链?以及如何使用Starport或Cosmos SDK运行多节点区块链?

Great question! Let's break this down into two clear sections—first using Starport (the streamlined tool built for Cosmos chains) which simplifies most of the setup, then covering the manual Cosmos SDK approach for when you need full control over every step.

1. Running a Multi-Node Blockchain with Starport

Starport abstracts away a lot of repetitive config work, making multi-node setups quick to spin up. Here's your step-by-step guide:

  • Prerequisite: Make sure Starport is installed (check with starport version; if not, follow the official install steps for your OS).
  • Initialize your chain project:
    starport scaffold chain mychain
    cd mychain
    
  • Start your first (main) node:
    Run starport chain serve—this will auto-generate keys, create the genesis file, and start the node. Note down:
    • The main node's moniker (default is mychain)
    • The node ID (displayed in the logs, or fetch later with starport tendermint show-node-id)
    • The P2P address (usually tcp://127.0.0.1:26656)
  • Set up the second node:
    Open a new terminal, navigate back to your mychain directory, then:
    1. Generate a new key for the second node:
      starport keys add node2
      
    2. Initialize the second node's config (use a custom home directory to avoid overwriting the main node's files):
      starport chain init node2 --home ./node2
      
    3. Copy the main node's genesis file to the second node (this ensures both nodes start with the same state):
      cp ~/.mychain/config/genesis.json ./node2/config/
      
    4. Fix port conflicts (each node needs unique ports):
      Edit ./node2/config/config.toml and update these values:
      • proxy_app = "tcp://127.0.0.1:26668" (changed from 26658)
      • laddr = "tcp://127.0.0.1:26667" (changed from 26657)
      • p2p.laddr = "tcp://0.0.0.0:26666" (changed from 26656)
    5. Add the main node as a seed for the second node:
      In ./node2/config/config.toml, find the seeds field and set it to:
      seeds = "<main-node-id>@127.0.0.1:26656"
      
      Replace <main-node-id> with the node ID you noted earlier.
    6. Start the second node:
      starport chain start --home ./node2
      
  • Verify synchronization:
    Send a test transaction from the main node's account to the second node's account:
    starport tx bank send alice <node2-address> 100stake --chain-id mychain-1
    
    Then check the balance on the second node:
    starport query bank balances <node2-address> --home ./node2
    
    If the balance updates, your nodes are syncing correctly!
2. Running a Multi-Node Blockchain with Cosmos SDK (Manual Approach)

If you want to skip Starport and work directly with the Cosmos SDK, here's how to set up a multi-node chain manually:

  • Prerequisite: Have a Cosmos SDK-based chain project (you can use the official template: clone it, build with make install, and ensure the chain binary is in your PATH). We'll use mychaind as the chain binary name here.
  • Set up the main node:
    1. Initialize the main node:
      mychaind init main-node --chain-id mychain-1
      
    2. Add a genesis account:
      mychaind keys add main-account
      mychaind add-genesis-account main-account 100000000stake
      
    3. Generate and collect the genesis transaction:
      mychaind gentx main-account 10000000stake --chain-id mychain-1
      mychaind collect-gentxs
      
    4. Start the main node:
      mychaind start
      
      Fetch the node ID with mychaind tendermint show-node-id and note the P2P address (tcp://127.0.0.1:26656 by default).
  • Set up the second node:
    Open a new terminal, then:
    1. Initialize the second node with a custom home directory:
      mychaind init node2 --chain-id mychain-1 --home ./node2
      
    2. Add a key for the second node:
      mychaind keys add node2-account --home ./node2
      
    3. Copy the main node's genesis file:
      cp ~/.mychaind/config/genesis.json ./node2/config/
      
    4. Resolve port conflicts:
      Edit ./node2/config/config.toml and update:
      • proxy_app = "tcp://127.0.0.1:26668"
      • laddr = "tcp://127.0.0.1:26667"
      • p2p.laddr = "tcp://0.0.0.0:26666"
        Then edit ./node2/config/app.toml to update:
      • grpc.address = "0.0.0.0:9091"
      • api.address = "tcp://0.0.0.0:1318"
    5. Add the main node as a seed:
      In ./node2/config/config.toml, set:
      seeds = "<main-node-id>@127.0.0.1:26656"
      
    6. Start the second node:
      mychaind start --home ./node2
      
  • Check sync status:
    Run mychaind status --home ./node2 and compare the latest_block_height with the main node's status. If they match, your nodes are in sync. You can also send a test transaction like in the Starport section to confirm functionality.

Pro Tips

  • For remote nodes (not on the same machine), replace 127.0.0.1 with the main node's public IP and ensure ports 26656 (P2P) are open in firewalls.
  • Always keep your mnemonics secure—never share them publicly.
  • If you run into sync issues, check the logs for errors (look for connection refused or port conflicts first).

内容的提问来源于stack exchange,提问作者Sandeep Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 03:13:14