Failed to get Xrpl NFt history using JSON RPC request's "nft_history" method

35 views Asked by At

Hello community memebers,

I'm unable to get the NFT history.

I tried to get the NFT history throgh the below given snippet.

from django.http import JsonResponse

def get_nfthistory(request):
    JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"

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

    nft_id = request.POST.get('nft_id')  

    # Initialize JSON-RPC client
    client = JsonRpcClient(JSON_RPC_URL)
    print(client)

    try:
        response_data = client.request(NFTHistory(nft_id=nft_id))
        print(response_data)

        return JsonResponse({'success': True, 'data': response_data})

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

I've written this django view function in order to get NFT history. I took XRPL NFT History method as reference.

And, the **NFTHistory ** in the "response_data = client.request(NFTHistory(nft_id=nft_id))" is a standard class defined in the xrpl model package. Here is the class code:

"""
The `nft_history` method retreives a list of transactions that involved the
specified NFToken.
"""
from dataclasses import dataclass, field
from typing import Any, Optional

from xrpl.models.requests.request import LookupByLedgerRequest, Request, RequestMethod
from xrpl.models.required import REQUIRED
from xrpl.models.utils import require_kwargs_on_init


@require_kwargs_on_init
@dataclass(frozen=True)
class NFTHistory(Request, LookupByLedgerRequest):
    """
    The `nft_history` method retreives a list of transactions that involved the
    specified NFToken.
    """

    method: RequestMethod = field(default=RequestMethod.NFT_HISTORY, init=False)
    nft_id: str = REQUIRED  # type: ignore
    """
    The unique identifier of an NFToken.
    The request returns past transactions of this NFToken. This value is required.

    :meta hide-value:
    """

    ledger_index_min: Optional[int] = None
    ledger_index_max: Optional[int] = None
    binary: bool = False
    forward: bool = False
    limit: Optional[int] = None
    # marker data shape is actually undefined in the spec, up to the
    # implementation of an individual server
    marker: Optional[Any] = None

I'm getting " Response(status=<ResponseStatus.ERROR: 'error'>, result={'error': 'unknownCmd', 'error_code': 32, 'error_message': 'Unknown method.', 'request': {'binary': False, 'command': 'nft_history', 'forward': False, 'nft_id': '0008000A3DDDE577DA6B1795E8919716D2C41BCB4AEFF7475B974D9F00000004'}}, id=None, type=<ResponseType.RESPONSE: 'response'>) " as response.

So could anyone help me fix this issue?

Thanks in advance.

1

There are 1 answers

0
nixer On

to use the nft_history command, the node has to be a Clio node (https://xrpl.org/the-clio-server.html).

Normal rippled nodes do not support this command.

And I can confirm that the testnet node you are connected to does not run / have a Clio server/node).

You can verify this by sending a command to the node and if the result includes such a message:

  "warnings": [
    {
      "id": 2001,
      "message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
    }
  ]

Then it is a Clio node. If the response does not include such a message, it is NOT a clio node.

And tbh I am not aware of any public Clio nodes for the testnet.