XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.19k stars 507 forks source link

Discrepancy in Wallet Address Generation from Seed on Mainnet #2696

Closed manuelreina closed 1 month ago

manuelreina commented 1 month ago

Description: First of sorry if this is not the place where I should put this. I am newbie to both the Block chain technology and the Ripple ecosystem. I am developing a very simple app to understand concepts and use it to manage my XRP accounts and I wondered if you could help spot what I am doing wrong. I encountered an issue trying to send transactions in the Mainnet (wss://s2.ripple.com:51233/), although the same code works in Test (wss://s.altnet.rippletest.net:51233). The error I get is an "RippleError - Account not found" and the looks to be focused on the Wallet.fromSeed method in the xrpl library which returns a wallet apparently new instead of my actual wallet. It's a paper wallet I have and the thing is that when I use an XRP wallet app like Xaman (introducing the same Seed) it works.

Steps to Reproduce: Send a transaction to a Kraken account (including the destination tag), using the below code.

Expected Behavior: Successful transaction to the chosen destination address

Actual Behavior: Error sending transaction. The wallet retrieved from the provided Seed is not my wallet and the code throws a RippleError - Account not found.

Environment: OS: Windows 10 Node Version: 16.16.0 XRPL Version: 3.0.0

Code & Error The code I use to send the transaction is very simple, and it needs to be improved with validations, etc, but as I mentioned it works connecting to Test.

try {
  await client.connect();

  const wallet = Wallet.fromSeed(secret);

  const txJson = {
    TransactionType: 'Payment',
    Amount: xrpl.xrpToDrops(amount),
    Destination: destination,
    Account: wallet.classicAddress,
  };

  if (destinationTag) {
    txJson.DestinationTag = parseInt(destinationTag);
  }

  console.log(txJson);
  const response = await client.submit(txJson, { wallet });
  console.log(response);

  const txResult = response.result?.meta?.TransactionResult || response.result?.engine_result || ''; // Response format: https://xrpl.org/transaction-results.html

  if (txResult === 'tesSUCCESS') {
    setMessage('Transaction submitted successfully!');
  } else {
    throw new Error(txResult);
  }
} catch (error) {
  console.log(error);
  setMessage('Error submitting transaction, Please try again.');
}

This is the tx object that I send: image

And this is the error that I get: image

manuelreina commented 1 month ago

Thanks for your message @intelliot I have just realized that I haven't explained myself with clarity. Although the above description covers what I am trying to do and the issue itself, I see that is not very well explained.

I have created this codesandbox to show exactly where I am encountering the issue.

Summary:

  1. I am developing a XRP wallet
  2. When I use the Send transaction functionality of the app I am developing it fails (RippleError: Account not found)
  3. The issue is related with the Paper wallet I am trying to send the XRPs from.
  4. The codesanbox shows how I am getting the wallet before sending the transacation.

Issue Details:

pdp2121 commented 1 month ago

@manuelreina Welcome!

On xrpl.js v3, by default the Wallet uses an ED25519 encoding instead of the older but less performant Secp256k1 encoding. When generating your wallet, please specify algorithm = ECDSA.secp256k1. Please let me know if that resolves your issue.

manuelreina commented 1 month ago

@pdp2121 Thank you very much! That was the problem. I will specify the old enconding until I have time to extend the method with functionality to handle multiple encoding scenarios. Thanks again! 🙂