Web interface component that provides the UI for the NEAR wallet adapter. This package is designed to work in conjunction with @fastnear/wallet-adapter.
The adapter-widget relationship works like this:
@fastnear/wallet-adapter
is used in your dApp to handle wallet interactions- When a wallet operation is needed, the adapter creates an iframe pointing to this widget
- This widget provides the UI for wallet selection and transaction signing
- The widget communicates back to your dApp through the adapter using postMessage
Build and deploy this widget to a static hosting service:
# Build the widget
npm run build
# Deploy contents of dist/ to your hosting
In your dApp, install and configure the adapter:
npm install @fastnear/wallet-adapter
import { WalletAdapter } from '@fastnear/wallet-adapter';
const adapter = new WalletAdapter({
// Point to your hosted widget
widgetUrl: 'https://your-domain.com/wallet-widget'
});
// The adapter will now use your hosted widget for wallet operations
await adapter.signIn({
networkId: 'mainnet',
contractId: 'example.near'
});
When developing locally:
# Install dependencies
npm install
# Start development server
npm run dev
# Widget will be available at http://localhost:3000
Then configure the adapter to use your local widget:
const adapter = new WalletAdapter({
widgetUrl: 'http://localhost:3000'
});
The widget must expose two HTML pages:
/login.html
- Wallet selection interface/sign.html
- Transaction signing interface
The adapter will automatically load the appropriate page based on the requested operation.
For production use:
-
Build the widget:
npm run build
-
Deploy the contents of the
dist
directory to your chosen hosting service -
Update your dApp's adapter configuration to use the production widget URL
- The widget should be hosted on a trusted domain
- HTTPS is required for production use
- Consider setting appropriate CORS and CSP headers
- The adapter's
targetOrigin
should be configured to match your widget's domain