UX.SOL

Hook

useRecipientValidation

Runs local recipient safety rules and inspects the real Solana account through @solana/kit RPC without requiring a wallet connection or identity provider.

Installation

terminal
$npx shadcn@latest add https://uxdotsol.xyz/r/use-recipient-validation.json

Usage

use-recipient-validation.tsx
"use client";
 
import { useRecipientValidation } from "@/hooks/uxdotsol/use-recipient-validation";
 
export function RecipientStatus({ recipient }: { recipient: string }) {
const validation = useRecipientValidation(recipient, {
rpcEndpoint: "https://api.devnet.solana.com",
});
 
return (
<div aria-live="polite">
<p>Status: {validation.status}</p>
{validation.reasons.map((reason) => (
<p key={reason.code}>{reason.message}</p>
))}
</div>
);
}

Options

NameTypeDefaultDescription
recipientstring | null | undefinedrequiredRecipient address to validate. Empty input keeps the hook idle.
rpcEndpoint / connectionstring / { rpcEndpoint: string } | nullundefinedDirect RPC endpoint or a compatible wallet-adapter Connection used for the real account lookup.
sender / allowSelfstring | { toString(): string } | null / booleanundefined / falseOptional sender and explicit policy for self-transfers.
requireExistingAccount / blockExecutableAccountsboolean / booleanfalse / truePolicies for new addresses and executable program accounts.
blockedAddresses / trustedAddressesreadonly string[] / readonly string[][] / []Application-owned recipient policy lists.
commitment / debounceMs / enabledCommitment / number / boolean'confirmed' / 300 / trueRPC commitment, lookup debounce, and hook enablement.

Functions

NameTypeDefaultDescription
refetch() => void-Repeats the RPC lookup for the current recipient.
validateRecipientAddress(recipient, options?) => RecipientLocalValidation-Runs the synchronous address, sender, trust-list, and block-list checks without React or RPC.

Types

NameTypeDefaultDescription
RecipientValidationStatus'idle' | 'invalid' | 'checking' | 'safe' | 'warning' | 'blocked' | 'error'-Small status vocabulary for recipient safety UI.
RecipientValidationReason{ code; severity; message }-Explainable local or RPC signal.

Returns

NameTypeDefaultDescription
status / reasonsRecipientValidationStatus / RecipientValidationReason[]'idle' / []Normalized result and explanations.
accountExists / executable / owner / lamportsboolean | null / boolean | null / string | null / bigint | nullnullCurrent account properties read from Solana RPC.
isValidAddress / isLoading / isSafe / canSubmitbooleanfalseConvenience flags for form and flow orchestration.
errorError | nullnullRPC lookup failure, when present.