React provider and hook for XRPL dApps using DropFi wallet
npm install @dropfi/xrpl-react> React context + hook to access DropFi Wallet via window.xrpl
- โ
Auto-initializes the injected window.xrpl provider (extension or mobile)
- โ
Provides connect, disconnect, sendTransaction, and signMessage
- โ
React hook with address, network, connectedAccounts, and more
- โ
Compatible with both browser extension and mobile webview injection
---
``bash`
pnpm add @dropfi/xrpl-react
> Requires the DropFi wallet to be injected as window.xrpl โ via Chrome extension or React Native WebView.
---
`tsx
import { XrplProvider, useXrplReact } from '@dropfi/xrpl-react';
export default function App() {
return (
);
}
function SomeComponent() {
const { address, connect, disconnect } = useXrplReact();
return (
Address: {address ?? 'Not connected'}
---
๐ API
$3
Returns:
`ts
{
address: string | undefined;
wallet: string | undefined;
isConnected: boolean;
connect: () => Promise;
disconnect: () => Promise;
sendTransaction: (tx: any) => Promise;
signMessage: (message: string) => Promise<{ signature: string }>;
changeNetwork: (network: string) => Promise;
connectedAccounts: string[];
network: string;
isConnecting: boolean;
error: string | null;
initialized: boolean;
}
`---
๐ง Events
These are internally emitted and listened to:
-
xrpl_selectedAddress
- xrpl_connectedAccounts
- xrpl_selectedNetwork
- xrpl_disconnect---
๐ Requirements
Make sure your app runs in an environment where
window.xrpl is available. This is injected by the DropFi wallet:- Chrome extension
- React Native mobile app via WebView
---
---
title: XRPL Transactions
description: How to use
sendTransaction and supported XRPL transaction types in @dropfi/xrpl-react.---
import { Highlight } from '@theme-ui/components'
๐ค Sending XRPL Transactions
The
useXrpl hook provided by @dropfi/xrpl-react includes a powerful sendTransaction function that allows you to send XRPL transactions directly from your React app using the connected wallet.`tsx
const { sendTransaction } = useXrpl();
`---
โ๏ธ Supported Transaction Types
You can send any valid XRPL transaction using
sendTransaction. Common supported types include:-
Payment
- TrustSet
- AccountSet
- OfferCreate
- OfferCancel
- NFTokenMint
- NFTokenBurn
- NFTokenCreateOffer
- NFTokenCancelOffer
- NFTokenAcceptOffer
- SetRegularKey
- SignerListSet
- EscrowCreate
- EscrowCancel
- EscrowFinish
- DepositPreauth
- CheckCreate
- CheckCash
- CheckCancel
- TicketCreate
- AccountDelete
- PaymentChannelCreate
- PaymentChannelFund
- PaymentChannelClaim
- AMMCreate
- AMMDeposit
- AMMWithdraw
- AMMVote_For full documentation, see the XRPL Transaction Types._
---
๐ธ Example: Sending a Payment
`ts
const tx: Payment = {
TransactionType: 'Payment',
Account: wallet.address,
Destination: 'rDestinationAddressHere',
Amount: '1000000', // 1 XRP in drops
};await sendTransaction(tx);
`---
๐งพ Example: NFTokenCreateOffer
`ts
const tx: NFTokenCreateOffer = {
TransactionType: 'NFTokenCreateOffer',
Account: nft.owner,
NFTokenID: nft.NftId,
Destination: 'rBrokerAccountHere',
Flags: 0x00000001, // 1 = sell offer
};await sendTransaction(tx);
`---
๐ Notes
- Every transaction must include the
TransactionType and Account fields.
- Amounts must be specified in drops for XRP or as { currency, issuer, value }` for tokens.> Need more examples? Check the xrpl.org transaction explorer or open an issue.
MIT ยฉ Travis Delly