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

如何运行Cardano Wallet?已完成安装但无法通过Node.js交互的技术求助

How to Run Cardano Wallet and Interact with It via Node.js

Got it, let's walk through how to get your Cardano Wallet service up and running, then make sure your Node.js code can connect to it properly.

Step 1: Start the Cardano Wallet Service

First, you need a fully synced Cardano node running in the background—Cardano Wallet relies on connecting to a live node to function. Once your node is up and synced, use the appropriate command to start the wallet service based on your network:

For Mainnet

cardano-wallet serve \
  --mainnet \
  --node-socket /path/to/your/cardano-node/db/socket \
  --port 1337

Replace /path/to/your/cardano-node/db/socket with the actual path to your Cardano node's socket file (this is usually located in your node's database directory).

For Testnets (e.g., Preprod)

cardano-wallet serve \
  --testnet /path/to/your/testnet-config.json \
  --node-socket /path/to/your/cardano-node/db/socket \
  --port 1337

You’ll need the configuration file for your target testnet (like Preprod or Preview) to use this command.

When the service starts successfully, you’ll see log messages confirming it’s listening on http://127.0.0.1:1337 and connected to your Cardano node.

Step 2: Verify the Wallet Service is Working

Before running your Node.js code, test the service directly with curl to make sure it’s responsive:

curl http://127.0.0.1:1337/v2/network/information

If you get a JSON response with network details, the service is ready to go.

Step 3: Tweak Your Node.js Code

Your existing code is almost there, but adding error handling will help you debug any connection issues. Here’s an improved version:

const { WalletServer } = require('cardano-wallet-js');
let walletServer = WalletServer.init('http://127.0.0.1:1337/v2');

async function test() {
  try {
    let information = await walletServer.getNetworkInformation();
    console.log('Network Information:', information);
  } catch (error) {
    console.error('Failed to connect to Cardano Wallet:', error.message);
    // If you need more details, uncomment the line below:
    // console.error('Full error:', error);
  }
}

test();

Also, double-check that you’ve installed the cardano-wallet-js package correctly:

npm install cardano-wallet-js

Common Troubleshooting Tips

  • Connection refused error: Make sure the wallet service is actually running, the port 1337 matches what you specified in the serve command, and your firewall isn’t blocking the port.
  • Node sync error: If the wallet service complains about the node not being synced, wait for your Cardano node to finish syncing completely before restarting the wallet service.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 17:02:31