XRPLF / xrpl.js

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

Cannot 'getAccountInfo' on newly generated xAddress #1638

Closed ajohnson1031 closed 2 years ago

ajohnson1031 commented 2 years ago

Hi,

I'm attempting to generate an xAddress and then immediately grab the accountInfo for it like so:

const RippleAPI = require("ripple-lib").RippleAPI;

const api = new RippleAPI({
  server: "wss://s.altnet.rippletest.net/",
  connectionTimeout: 10000,
});

(async () => {
  const address = await api.generateXAddress({ test: true });
  console.log(address);
  if (address) {
    const accountInfo = await api.getAccountInfo(address.xAddress);
    console.log(accountInfo);
  }
})();

However it returns an account not found error:

RippledError: Account not found.
    at RequestManager.handleResponse (/Users/xxxxx/node_modules/ripple-lib/dist/npm/common/connection.js:189:27)
    at Connection._onMessage (/Users/xxxxx/node_modules/ripple-lib/dist/npm/common/connection.js:281:38)
    at WebSocket.<anonymous> (/Users/xxxxx/node_modules/ripple-lib/dist/npm/common/connection.js:357:54)
    at WebSocket.emit (node:events:365:28)
    at WebSocket.emit (node:domain:470:12)
    at Receiver.receiverOnMessage (/Users/xxxxx/node_modules/ws/lib/websocket.js:835:20)
    at Receiver.emit (node:events:365:28)
    at Receiver.emit (node:domain:470:12)
    at Receiver.dataMessage (/Users/xxxxx/node_modules/ws/lib/receiver.js:437:14)
    at Receiver.getData (/Users/xxxxx/node_modules/ws/lib/receiver.js:367:17) {
  data: {
    account: 'rfyu6h6avXHYnjQxCxEfjP4pXx2yrtBd66',
    error: 'actNotFound',
    error_code: 19,
    error_message: 'Account not found.',
    id: 1,
    ledger_hash: 'D43848BF1163A68B5F873336521C802AB9A70EBCD0BDBE013908A1335C10C05A',
    ledger_index: 21166032,
    request: {
      account: 'rfyu6h6avXHYnjQxCxEfjP4pXx2yrtBd66',
      command: 'account_info',
      id: 1,
      ledger_index: 'validated'
    },
    status: 'error',
    type: 'response',
    validated: true
  }
}

Is this expected behaviour for the testnet and will it be resolved in production, or is my expectation flawed, specifically, that I should be able to grab the details of the account upon creation.

Many thanks for any advice.

mvadari commented 2 years ago

The account has technically not been created yet - it needs to be funded with some XRP (see https://xrpl.org/accounts.html#creating-accounts). There are some XRP faucets on the testnet that you can use, and a function in ripple-lib v1.10.0 that calls the faucets (api.generateFaucetWallet).

intelliot commented 2 years ago

generateXAddress does create a keypair and address, but these are local to your machine. No one else knows about the address/account until it is created on the ledger by receiving a payment of at least the account reserve. getAccountInfo retrieves information from the global ledger, so it will only return account details for addresses that have been created (funded).

ajohnson1031 commented 2 years ago

Thanks @mvadari and @intelliot. This is very helpful information. Reading up on the topic now.

mvadari commented 2 years ago

Going to assume that this has been resolved. If it hasn't, please reopen the issue.