

Connect and make a wallet
Open a connection, then get a test wallet. Keep every real secret out of code.
Key points
- One Client connects to one server over a WebSocket.
- fundWallet gives a throwaway Testnet wallet with test XRP.
- Never paste a real secret into code. Load test seeds from outside.
The lesson
A program talks to the ledger through a server. In , a Client holds that connection. It stays open, like a phone call, so answers and news can flow both ways.
Next you need a wallet: a and its . On , the can make one for you and fill it with test XRP. Use it, then throw it away.
A wallet comes from a , a secret string that starts with "s". Anyone with the seed controls the account.
So never paste a real seed into code. Code gets shared, copied and pushed online. Bots scan public code for secrets all day.
For practice, use faucet wallets. If a program must reuse a test wallet, load its seed from outside the code. For real money, let a wallet app like Xaman or Joey do the signing.
Connect:
import { Client, Wallet } from "xrpl" const client = new Client("wss://s.altnet.rippletest.net:51233") await client.connect()client.isConnected()reports the state. Callclient.disconnect()when done.A throwaway wallet:
const { wallet, balance } = await client.fundWallet() console.log(wallet.address, balance) // r... and the test XRP receivedReuse a test wallet, with the kept out of the code:
const wallet = Wallet.fromSeed(process.env.TESTNET_SEED)Keep the variable in a
.envfile listed in.gitignore, or in a secret store.Keys.
Wallet.generate()makes a new offline. It uses Ed25519 by default, so its seed starts withsEd.Wallet.fromSeed()rebuilds the same keys and from a seed. A new wallet is only a key pair. A payment of the base reserve makes it an account.Related: Keys and secrets, Activating an account.

