XRPLF / rippled

Decentralized cryptocurrency blockchain daemon implementing the XRP Ledger protocol in C++
https://xrpl.org
ISC License
4.53k stars 1.47k forks source link

After minting NFT, sometimes latest minted NFT don't appears in account NFT using xrpl.js version-2.6.0 #4502

Open KumarUjjwal2022 opened 1 year ago

KumarUjjwal2022 commented 1 year ago

Hi Team,

I am using xrpl npm version 2.6.0 in NodeJS to make XRPL NFT Exchange. After performing minting operation when i find accounts latest minted NFT with help of URI passed in JSON object while minting, sometimes ledger provide latest minted NFT and sometimes its undefined. And When ledger fails to provide us latest minted NFT We are not able to perform further operation.

Sometimes we thought that ledger might take sometime to updated minted NFT in accounts NFT page so we added setTimeout but no effect of that.

So Someone please help or suggest the correct process if i am doing something wrong. Thanks in advance for suggestion or any help. I am providing code below So that if anything wrong can correct me.

I am using windows system with NodeJS version 14.17.6 and xrpl version - 2.6.0

Code is mentioned below:- try { const { _id, TransferFee,flag } = req.body; const { ac, it } = req.decoded; const getnfts = await Nft.findById(_id).select({ image: 1, _id: 0, metaDataUrl: 1 }); const request = { txjson: { TransactionType: "NFTokenMint", Account: ac, URI: getnfts.metaDataUrl ? xrpl.convertStringToHex(getnfts.metaDataUrl) : xrpl.convertStringToHex(getnfts.image), Flags: parseInt(flag), NFTokenTaxon: 0, TransferFee: parseInt(TransferFee) }, user_token: it, };

const subscription = await Sdk.payload.createAndSubscribe(
  request,
  (event) => {
    if (event.data.signed === true) {
      return event.data;
    }
    if (event.data.signed === false) {
      return false;
    }
  }
);
const resolveData = await subscription.resolved;
if (resolveData.signed !== true) {
 console.log("error", resolveData.signed)
}

setTimeout(async()=>{
  await client.connect();
  const nftsMintedData = await client.request({ method: "account_nfts", account: ac, });
  client.disconnect();
  let myarray = nftsMintedData.result.account_nfts;
  const { URI: latesUrl } = request.txjson;
  const item = myarray.find(vl => vl.URI.includes(latesUrl));
 console.log("minted nft", item)
},6000)

} catch (error) { console.log("error===mint====", error); }

ckniffen commented 1 year ago

I don't believe response of account_nfts is in minted order. That means you will have to keep following the marker field until you find the newly added NFToken.

Is this happening in cases where marker is not returned? Also are you using submitAndWait?

shawnxie999 commented 1 year ago

Could you elaborate on your intention? If you are trying to find the NFTokenID of the latest mint, then using account_nfts is not the right way to retrieve the new NFT minted.

The right way to get the NFTokenID is to call tx API using the hash returned from the NFTokenMint you submitted. Then you need to use getNFTokenID to find the new NFTokenID

Currently you seem to be fetching the first page of account_nfts, however, this API does not promise that the latest NFToken minted is on the first page (account_nfts has pagination where you can use the marker from the response to find subsequent page). Even if you are trying to use the URI to find the NFTokenID, you would need to iterate through all pages of account_nfts in order to find the latest NFT minted, not just the first page. But I would avoid using account_nfts, because this API is only used for finding all the NFTs you own, not to search for the NFTs you minted.

KumarUjjwal2022 commented 1 year ago

Thanks both of you @ckniffen @shawnxie999 for the help.

@shawnxie999 I was going through your above mentioned process to get NFTokenID after minting NFT. I just used this url "https://xrpl.org/websocket-api-tool.html#tx" to get txid details which i got as a response after minting process. And I got few values after hitting above mentioned url. The values i got are "Account", "Fee", "Flags", "LastLedgerSequence", "NFTokenTaxon", "Sequence", "SigningPubKey", "TransactionType", "TransferFee", "TxnSignature", "URI", "date", "hash", "inLedger", "ledger_index" and also some more values including some NFTokens.

But after this process I'm confused little bit as i couldn't get the method you mentioned above i.e. getNFTokenID in XRPL npm or in XRPL documentation.

So can you explain little bit more to get latest minted NFT, Process I'm using is mentioned in above issue description if you could write the script to find latest minted NFT then it would be great for me. I'm using NodeJS for api.

shawnxie999 commented 1 year ago

@KumarUjjwal2022 I've attached a function getNFTokenID in the script below that exercises similar logic as what I linked you, feel free to copy it into your code. Essentially this function takes in the meta field of the response, and performs calculation to find out the new NFT minted.

As for the availability of getNFTokenID in client library, I'm not too sure about this, perhaps @ckniffen could help.

  const getNFTokenID = (meta) => {
    const affectedNodes = meta.AffectedNodes.filter(
      (node) =>
        node.CreatedNode?.LedgerEntryType === "NFTokenPage" ||
        (node.ModifiedNode?.LedgerEntryType === "NFTokenPage" &&
          !!node.ModifiedNode?.PreviousFields.NFTokens)
    );

    const previousTokenIDSet = new Set(
      affectedNodes
        .flatMap((node) =>
          node.ModifiedNode?.PreviousFields?.NFTokens?.map(
            (token) => token.NFToken.NFTokenID
          )
        )
        .filter((id) => id)
    );

    const finalTokenIDs = affectedNodes
      .flatMap((node) =>
        (
          node.ModifiedNode?.FinalFields ?? node.CreatedNode?.NewFields
        )?.NFTokens?.map((token) => token.NFToken.NFTokenID)
      )
      .filter((id) => id);

    const tokenID = finalTokenIDs.find((id) => !previousTokenIDSet.has(id));

    return tokenID;
  };

  // Response  you get from `tx` response
  const txResponse = {
    result: {
      Account: "rB1ZB8H9FTxW3dMCMYDW2thuiGyL38Yx5j",
      Fee: "10",
      Flags: 8,
      LastLedgerSequence: 2286,
      NFTokenTaxon: 0,
      Sequence: 2265,
      SigningPubKey:
        "ED6B1029DDD445952E1B849A24ADF2D7C42FE53953ED36A62502C8C2B53C8FF9CF",
      TransactionType: "NFTokenMint",
      TxnSignature:
        "3727B51FAC82F98FB8ED46BF8640119DBA929B2196C09F8715160FAB163B0DF20697CC2DB6F2E2BF0688A09F39BD79F3A93DA49437F70EB6F1979842515E5C06",
      URI: "68747470733A2F2F7872706C2E6F7267",
      date: 735332044,
      hash: "43A957810A7690D82A3F834405FEEDA527BA20F45332B867A9AD71FE7F40BEC2",
      inLedger: 2267,
      ledger_index: 2267,
      meta: {
        AffectedNodes: [
          {
            ModifiedNode: {
              FinalFields: {
                Account: "rB1ZB8H9FTxW3dMCMYDW2thuiGyL38Yx5j",
                Balance: "99999990",
                Flags: 0,
                MintedNFTokens: 1,
                OwnerCount: 1,
                Sequence: 2266,
              },
              LedgerEntryType: "AccountRoot",
              LedgerIndex:
                "5187D567276B1B777FF4DE1BB7DEF0FBDB5C9BDCB9088B94EAABCAB44419B413",
              PreviousFields: {
                Balance: "100000000",
                OwnerCount: 0,
                Sequence: 2265,
              },
              PreviousTxnID:
                "5C435F48D16989F54D3429A226B777B91A77890BD546027B9EDDFC172FCFA293",
              PreviousTxnLgrSeq: 2265,
            },
          },
          {
            CreatedNode: {
              LedgerEntryType: "NFTokenPage",
              LedgerIndex:
                "7740EC601A4C7C544D079B719C9F9B12CF996A92FFFFFFFFFFFFFFFFFFFFFFFF",
              NewFields: {
                NFTokens: [
                  {
                    NFToken: {
                      NFTokenID:
                        "000800007740EC601A4C7C544D079B719C9F9B12CF996A920000099B00000000",
                      URI: "68747470733A2F2F7872706C2E6F7267",
                    },
                  },
                ],
              },
            },
          },
        ],
        TransactionIndex: 0,
        TransactionResult: "tesSUCCESS",
      },
      status: "success",
      validated: true,
    },
  };

  console.log(getNFTokenID(txResponse.result.meta));
ckniffen commented 1 year ago

It was added in xrpl@2.7.0 so you will need to bump your version. Here is the PR https://github.com/XRPLF/xrpl.js/commit/5d34746f1241cc17d5ad08e0c1d6aa63d6743e42

KumarUjjwal2022 commented 1 year ago

Thanks

KumarUjjwal2022 commented 1 year ago

Hey Team Thanks for your help , It's like half of my issue is resolved as i could get NFTokenID as per solution you guys have provided but didn't get NFTokenID details like issuer, nft serial number etc. I tried to get details with help of nft_info api keys give in XRPL documentation i.e. https://xrpl.org/nft_info.html but it gives me error like command not found , methods not found. I am trying to get NFTokens info in below mentioned ways:-

const txDetails = await client.request({ method: "tx", transaction: resolveData.txid, binary: false }); console.log(txDetails,"txresult") const nftId = await GetNftID.getNFTokenID(txDetails.result.meta); const nftsDetails = await client.request({ method: "nft_info", nft_id: nftId});

shawnxie999 commented 1 year ago

@KumarUjjwal2022 nft_info is a clio-only API. You can either run your own clio node, or connect to wss://s2-clio.ripple.com:51233 for the API

KumarUjjwal2022 commented 1 year ago

Okay thanks @shawnxie999 . I am using wss://xrplcluster.com/ to connect with ripple server. So what should i use to get single NFToken info/details if i use above url to connect with xrpl?

shawnxie999 commented 1 year ago

@KumarUjjwal2022 Ideally you should use both servers. Clio is only read-only, which means you can't submit transactions to it.

So, you should open a seperate WS to connect to clio exclusively to get the NFT details.

KumarUjjwal2022 commented 1 year ago

Thanks @shawnxie999 . I got the details also of NFTokenID but sometimes this error i get while minting and fetching NFT details:-

NotConnectedError: Error: connect() timed out after 8000 ms. If your internet connection is working, the rippled server may be blocked or inaccessible. You can also try setting the 'connectionTimeout' option in the Client constructor.

I have given connectionTimeout also while setting connection but there is not effect of that, I actually want to know when did this error comes??

const client = new xrpl.Client(process.env.XRPL_URI, { connectionTimeout: 8000, });

shawnxie999 commented 1 year ago

@ckniffen do you know what's happening?

ckniffen commented 1 year ago

I have never seen this.

shawnxie999 commented 1 year ago

@KumarUjjwal2022 are you sure it's not an internet/firewall issue? The server should work just fine. AFAIK, it shouldn't have caused by the library or the server

KumarUjjwal2022 commented 1 year ago

Not sure, that's why i asked from you guys. This error doesn't occurs always but it's random. Do we need to add some script to check internet speed and what speed does XRPL server need to perform all sort of transaction and operation?

shawnxie999 commented 1 year ago

@KumarUjjwal2022 Does this problem occur on all internet networks? Have you tried to connect to different wifi and check if the problem still persists?

KumarUjjwal2022 commented 1 year ago

@shawnxie999 To be honest i have been working on same network always. And i faced this issue random sometimes a day or in a week but it's not regular.

shawnxie999 commented 1 year ago

@KumarUjjwal2022 This problem was seen in the past where firewall blocks the connection. But you are experiencing it intermittently, it sounds like a internet problem but we don't really know for sure. I would try to test it on different networks when you get the chance.

intelliot commented 1 year ago

@KumarUjjwal2022 which rippled servers are you using?

It would be best to run your own rippled servers.

shawnxie999 commented 1 year ago

Okay thanks @shawnxie999 . I am using wss://xrplcluster.com/ to connect with ripple server. So what should i use to get single NFToken info/details if i use above url to connect with xrpl?

@intelliot

intelliot commented 1 year ago

@shawnxie999 thanks.

The recommendation to run your own rippled servers remains.

@WietseWind could it be useful to connect with @KumarUjjwal2022 (see above) to debug any potential connectivity issues?

TwoBigPaws133 commented 1 year ago

can anyone help please. after having an offer rejected for NFT i didnt get my reserve back on over 30 rejected offers?

WhatsApp Image 2023-06-24 at 16 48 24

scottschurr commented 1 year ago

@TwoBigPaws133, when you create an NFToken Offer, that offer remains in the ledger until it is either accepted or canceled. If you want to cancel your offers (and get your reserve back) here's information on the transaction that can do that: https://xrpl.org/nftokencanceloffer.html#example-nftokencanceloffer-json

TwoBigPaws133 commented 1 year ago

Thanks that is a cancelled rejected offer. this is the reason for my post. i have over 30 transactions that didnt give me the 2 XRP back. thanks for replying. onxrp site are not replying and its realliy frustrating.

TwoBigPaws133 commented 1 year ago

WhatsApp Image 2023-06-27 at 14 19 18 WhatsApp Image 2023-06-27 at 14 19 181 WhatsApp Image 2023-06-27 at 14 19 182 WhatsApp Image 2023-06-27 at 14 19 16

TwoBigPaws133 commented 1 year ago

I clicked on your link there was nothing in there that matches my issue?

WietseWind commented 1 year ago

It is impossible for a deleted account not to return your reserved XRP.

You are using Xumm (based on your screenshots). On the Xumm home screen, you can tap the Reserve to see a breakdown of your reserve. It will match the owned offers.

So there are two options:

You can use any transaction explorer, e.g. https://bithomp.com/ to confirm if the cancel transactions are actually executed successfully.

TwoBigPaws133 commented 1 year ago

This is why i am here my friend. the facts are as stated. i can tell you i am an outlier in all i do. just left dentist after five injections still feeling pain with a shocked dentist saying impossible. I am stating what happened. is there anywhere i can look because my balance did not increase. 100% and as repeated multiple times cancelling other bids it states cacelled. WhatsApp Image 2023-06-27 at 15 35 13 WhatsApp Image 2023-06-27 at 15 35 14

emphasis on the should. it never! someone please help me get to the bottom of this lol

WietseWind commented 1 year ago

Please note this doesn't show in Xumm or explorers as +2 XRP: the reserve is never deducted from the balance with -2: it's simply 'locked'. So cancelling the offer makes the 2 XRP spendable again, but it never left your wallet, and so isn't returned: it just becomes unspendable (locked) balance. As such, the Offer cancellation transaction doesn't show +2 XRP being added.

Regarding your specific transaction: (hash for reference, as I had to copy paste it from the screenshot) https://explorer.xrplf.org/tx/4BA1619CD080E0D8A82556B2C5B644A10112AC60AD655C565E292912A76A2931

Your TX doesn't contain a Deleted Node (the offer, resulting in a reserve change).

Based on the explorer screenshot for the offer: https://bithomp.com/en/nft-offer/C55CE3A7EB5645524B2AE10BCA3E853F1800AAAA17E79DE040EC34B50E5FFF9E

I notice the offer already expired:

image

Someone else already cleared your expired offer, resulting in the object already being deleted, resulting in your reserve already passively being increased because the offer was deleted before (not because of the transaction you initiated).

Your offer got cancelled in this transaction, together with a bunch of others, by another account: https://bithomp.com/explorer/44B37D45638014BA7A30F56D7D2876B29E7471E68FDF8B4DA0618EB4582604EB

This resulted in your reserve unlocking. So by the time you removed the offer, you removed an already removed object, resulting in just the TX Fee burn and not the object removal. Your reserve already increased before you actually removed the offer.

TwoBigPaws133 commented 1 year ago

Thank you ever so much for this detailed explination. please see further comments and confirm please. Transaction summary

Date:Jun 24, 2023, 10:47:30 AM UTCSource:raECmBiik2WqgHCLwSD1SSnn17pB9UXfC8SpecificationNFT CANCEL OFFERTx hash:D9450134E7F8337F15DCF8F3076136DBABD1B544C1FC39A99B80532340E7E700 MemosCreated on http://nft.onxrp.com OutcomeSUCCESSLedger:80,685,319Index:8Tx seq:67,748,876Fee:0.000015 XRP Raw JSON Sponsored:📷IBAN Accounts for Crypto Hodlers. Just like a Bank.Get your IBAN now → Affected Nodes Modified nodeLedgerEntryTypeACCOUNTROOTLedgerIndex587E28972F3B63D2260C0671E59593EE6C4D27AB857D1AF230F5CAA959BB3EACPreviousTxnIDC51F46F90022588648511AC97D1354A321F7F23EAF5BC9259E5A4C74C417C7EBPreviousTxnLgrSeq80,685,316 Modified nodeLedgerEntryTypeDIRECTORYNODELedgerIndex6F9128A77C80BB112E111F74A6474AEB11438577C7F4F249672F7D8C8C2A5DCB Modified nodeLedgerEntryTypeDIRECTORYNODELedgerIndexBC48013DB7164B248FA55C7D62CC598EC0F366EDE82ED79F139CCC0CA95FD00F Modified nodeLedgerEntryTypeACCOUNTROOTLedgerIndexC99E580539A5E84070D51FDD231667C52A444ECD50DFF5575D6568744B17DD19PreviousTxnID0268F349651E69A9A6957E6317DE483ADC65B8804F2F8259E9C4AC22AFB4BEF0PreviousTxnLgrSeq80,685,308 Deleted nodeLedgerEntryTypeNFTOKENOFFERLedgerIndexCD105E734DDE53A2101CBC7F85E39E0CB5CC2DEC630F973006813D8D26D8D900

this was a successfuly cancelled NFT offer as you can see there is so much more data including a section which states deleted.

here is one of the transactions in question. it shows far less data and doesnt have a deleted section so is this the reason why its not returned properly?

Transaction summary Date:Jun 24, 2023, 10:50:51 AM UTCSource:raECmBiik2WqgHCLwSD1SSnn17pB9UXfC8SpecificationNFT CANCEL OFFERTx hash:12E7506350ECA4A1A7CBB32E9EFBA2FE7C1AAEEAD5FCD50DB4BE201DB1CB3A86 MemosCreated on http://nft.onxrp.com OutcomeSUCCESSLedger:80,685,371Index:18Tx seq:67,748,879Fee:0.000015 XRP Raw JSON Sponsored:📷Get your IBAN for managing your FIAT & investing in Crypto.Learn more → Affected Nodes Modified nodeLedgerEntryTypeACCOUNTROOTLedgerIndexC99E580539A5E84070D51FDD231667C52A444ECD50DFF5575D6568744B17DD19PreviousTxnIDFD96FD9C94677569087616621FD9D042F059262CC702461D14894BAD0F53608BPreviousTxnLgrSeq80,685,351

thanks

WietseWind commented 1 year ago

The reason your transaction doesn't have the deleted element is because the first one already deleted it.

At delete the reserve is freed up because it removes one of your account's owned objects.

TwoBigPaws133 commented 1 year ago

Thank you very much for all your help

mvadari commented 1 year ago

This issue can be closed.

TwoBigPaws133 commented 1 year ago

Please close. Thank you.

On 1 Nov 2023, at 22:10, Mayukha Vadari @.***> wrote:

 This issue can be closed.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.