Documentation Index
Fetch the complete documentation index at: https://docs.argyros.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Wallet Integration
The widget does not bundle a wallet adapter. Instead, it exposes a setWallet() method and a connect-wallet event so you can plug in any wallet solution.
How It Works
- User clicks “Swap” (or “Connect”) with no wallet set
- Widget fires
connect-wallet event
- Your app handles the event, connects the wallet, and calls
widget.setWallet(address)
- Widget loads balances and enables swapping
setWallet(address)
Set the wallet address programmatically. When called with a non-empty address, the widget fetches native SOL balance and SPL token balances via the configured rpc-url.
const widget = document.querySelector("argyros-swap");
widget.setWallet("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM");
To disconnect:
connect-wallet Event
Fired when the user clicks the primary button but no wallet is connected. Listen for this to trigger your wallet adapter.
const widget = document.querySelector("argyros-swap");
widget.addEventListener("connect-wallet", async () => {
const wallet = await connectWallet(); // your wallet adapter
widget.setWallet(wallet.publicKey.toString());
});
Solana Wallet Adapter (React)
"use client";
import { useEffect, useRef } from "react";
import { useWallet } from "@solana/wallet-adapter-react";
import { useWalletModal } from "@solana/wallet-adapter-react-ui";
import "@argyros/widget";
export default function SwapWidget() {
const ref = useRef<HTMLElement>(null);
const { publicKey, connected } = useWallet();
const { setVisible } = useWalletModal();
// Sync wallet state to widget
useEffect(() => {
const el = ref.current as any;
if (!el) return;
if (connected && publicKey) {
el.setWallet(publicKey.toBase58());
} else {
el.setWallet("");
}
}, [connected, publicKey]);
// Handle connect-wallet event
useEffect(() => {
const el = ref.current;
if (!el) return;
const handler = () => setVisible(true);
el.addEventListener("connect-wallet", handler);
return () => el.removeEventListener("connect-wallet", handler);
}, [setVisible]);
return (
<argyros-swap
ref={ref}
api-key="argy_your_api_key"
chain="solana"
theme="dark"
/>
);
}
Phantom (Vanilla JS)
<script src="https://cdn.argyros.trade/argyros-widget.umd.js"></script>
<argyros-swap
api-key="argy_your_api_key"
chain="solana"
theme="dark"
></argyros-swap>
<script>
const widget = document.querySelector("argyros-swap");
widget.addEventListener("connect-wallet", async () => {
if (!window.solana?.isPhantom) {
window.open("https://phantom.app/", "_blank");
return;
}
const resp = await window.solana.connect();
widget.setWallet(resp.publicKey.toString());
});
// Auto-connect if already approved
if (window.solana?.isPhantom) {
window.solana.connect({ onlyIfTrusted: true })
.then((resp) => widget.setWallet(resp.publicKey.toString()))
.catch(() => {});
}
</script>
Balance Display
Once setWallet() is called with a valid address, the widget automatically:
- Fetches native SOL balance via
getBalance RPC call
- Fetches all SPL token balances via
getTokenAccountsByOwner
- Displays balances next to the selected input/output tokens
- Enables HALF and MAX buttons for quick amount entry
The RPC endpoint used is configured via the rpc-url attribute (defaults to https://mainnet.fogo.io/).