@fastnear/wallet
v2.3.0
Published
Multi-wallet connector for NEAR dApps — MyNearWallet, HERE, Meteor, and more
Readme
@fastnear/wallet
Multi-wallet connector for NEAR dApps. Supports MyNearWallet, HOT Wallet, Meteor, NEAR Mobile, WalletConnect, and more via @fastnear/near-connect.
Install
npm install @fastnear/walletUsage
import { connect, disconnect, sendTransaction, accountId } from "@fastnear/wallet";
// Show wallet picker and connect
const result = await connect({ network: "mainnet" });
console.log("Connected:", result.accountId);
// Send a transaction
await sendTransaction({
receiverId: "wrap.near",
actions: [
{ type: "FunctionCall", methodName: "near_deposit", args: {}, gas: "30000000000000", deposit: "1000000000000000000000000" }
],
});
// Disconnect
await disconnect();Agent-first tasks
When you pair @fastnear/wallet with @fastnear/api, the shortest task-oriented entrypoints are the wallet-backed recipes:
near.recipes.connectnear.recipes.functionCallnear.recipes.transfernear.recipes.signMessage
Connect a wallet
const result = await near.recipes.connect({
contractId: "berryclub.ek.near",
});
near.print(result ?? near.selected());Send a function call
const cu = near.utils.convertUnit;
const result = await near.recipes.functionCall({
receiverId: "berryclub.ek.near",
methodName: "draw",
args: {
pixels: [{ x: 10, y: 20, color: 65280 }],
},
gas: cu("100 Tgas"),
deposit: "0",
});
near.print(result);Transfer NEAR
const cu = near.utils.convertUnit;
const result = await near.recipes.transfer({
receiverId: "escrow.ai.near",
amount: cu("0.1 NEAR"),
});
near.print(result);Sign a message
const result = await near.recipes.signMessage({
message: "Sign in to FastNear Berry Club",
recipient: window.location.host,
nonce: crypto.getRandomValues(new Uint8Array(32)),
});
near.print(result);Restore session
import { restore } from "@fastnear/wallet";
// On page load, restore a previously connected wallet session
const result = await restore();
if (result) {
console.log("Restored session:", result.accountId);
}Timeout-aware delegate signing
signDelegateActions supports NEP-366 delegates with an explicit block-height
TTL. This is the bridge used by @fastnear/x402 to satisfy the x402 NEAR exact
scheme's expiry rules.
import * as nearWallet from "@fastnear/wallet";
await nearWallet.connect({
network: "testnet",
features: {
signDelegateActions: true,
signDelegateActionsWithTtl: true,
},
});
const result = await nearWallet.signDelegateActions({
network: "testnet",
delegateActions: [{
receiverId: "usdc.fakes.testnet",
blockHeightTtl: 300,
actions: [{
type: "FunctionCall",
params: {
methodName: "ft_transfer",
args: { receiver_id: "merchant.testnet", amount: "10000" },
gas: "30000000000000",
deposit: "1",
},
}],
}],
});The TTL is accepted only when the selected wallet explicitly advertises
signDelegateActionsWithTtl; missing capability fails before opening a signing
prompt. Compatible near-connect manifests and wallet releases are a prerequisite
for using this path in production.
Browser (IIFE)
<script src="https://cdn.jsdelivr.net/npm/@fastnear/wallet/dist/umd/browser.global.js"></script>
<script>
// Available as window.nearWallet
// Auto-wires with @fastnear/api if loaded
nearWallet.connect({ network: "mainnet" });
</script>WalletConnect support is excluded from the IIFE bundle to keep it small (~100 KB). Load @walletconnect/sign-client separately if needed.
Part of the FastNear JS monorepo
See the project-level README for more info.
