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

使用JSON RPC的nft_history方法获取XRPL NFT历史失败求助

解决XRPL nft_history RPC命令返回unknownCmd错误的问题

你遇到的Unknown method(error_code 32)错误,核心原因是当前请求的XRPL测试网节点不支持nft_history这个RPC方法。nft_history属于XRPL的NFT扩展功能,需要节点在启动时启用NFTSupport插件才能提供该命令,而你使用的公共测试网节点(https://s.altnet.rippletest.net:51234/)默认未开启该插件。

解决方案

1. 更换支持NFT历史查询的节点

使用已启用NFTSupport插件的XRPL节点,有两种方式:

  • 自行搭建本地XRPL节点,在rippled.cfg配置文件中添加以下内容后重启节点:
    [plugins]
    NFTSupport
    
  • 使用第三方提供的已启用NFT支持的测试网节点。

2. 升级xrpl-python库

确保你使用的xrpl-py是最新版本,避免因版本兼容问题导致的方法定义异常:

pip install --upgrade xrpl-py

3. 优化视图函数的序列化逻辑

当前代码直接返回XRPL的Response对象会导致Django序列化失败,建议转换为字典后返回:

from django.http import JsonResponse
from xrpl.clients import JsonRpcClient
from xrpl.models.requests import NFTHistory

def get_nfthistory(request):
    # 替换为支持nft_history的节点地址
    JSON_RPC_URL = "https://your-nft-enabled-node:51234/"

    if request.method != 'POST':
        return JsonResponse({'success': False, 'error': 'Invalid request method'})

    nft_id = request.POST.get('nft_id')  
    if not nft_id:
        return JsonResponse({'success': False, 'error': 'nft_id is required'})

    client = JsonRpcClient(JSON_RPC_URL)

    try:
        response = client.request(NFTHistory(nft_id=nft_id))
        # 将Response对象转换为可序列化的字典
        response_dict = response.to_dict()
        return JsonResponse({'success': True, 'data': response_dict})

    except Exception as e:
        return JsonResponse({'success': False, 'error': str(e)})

4. 验证NFT ID有效性

确认传入的nft_id是符合XRPL规范的64位十六进制字符串,避免因无效ID导致的额外异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 14:55:12