本文へスキップ
Anon Wallet

DApp 統合ガイド

Anon Wallet は window.ethereum に標準 EIP-1193 プロバイダーを挿入します。MetaMask 対応 DApp の多くは変更なしで動作します。

検出

window.ethereum に次の属性を設定します。

window.ethereum.isAnon    // true
window.ethereum.isMetaMask  // true (for compatibility)

MetaMask と区別して Anon を検出するには isAnon を確認します。

if (window.ethereum?.isAnon) {
  console.log("Anon Wallet detected");
}

アカウントの要求

const accounts = await window.ethereum.request({
  method: "eth_requestAccounts",
});
// accounts[0] is the user's active public address

DApp のホスト名を示す承認画面が表示され、承認後にアカウントを返します。

取引の送信

const txHash = await window.ethereum.request({
  method: "eth_sendTransaction",
  params: [{
    from: accounts[0],
    to: "0xRecipient...",
    value: "0xde0b6b3a7640000", // 1 ETH in hex wei
    data: "0x",
  }],
});

承認画面で公開残高、またはシールド残高があり条件を満たす場合はプライベート残高を選択できます。

メッセージへの署名

// Personal sign
const signature = await window.ethereum.request({
  method: "personal_sign",
  params: ["Hello from my DApp", accounts[0]],
});

// EIP-712 typed data
const signature = await window.ethereum.request({
  method: "eth_signTypedData_v4",
  params: [accounts[0], JSON.stringify(typedData)],
});

ネットワーク切り替え

await window.ethereum.request({
  method: "wallet_switchEthereumChain",
  params: [{ chainId: "0xa4b1" }], // Arbitrum
});

要求されたチェーンが未設定なら、追加を案内します。

イベントリスナー

// Account changed
window.ethereum.on("accountsChanged", (accounts) => {
  console.log("Active account:", accounts[0]);
});

// Chain changed
window.ethereum.on("chainChanged", (chainId) => {
  console.log("Chain:", parseInt(chainId, 16));
});

// Connected
window.ethereum.on("connect", ({ chainId }) => {
  console.log("Connected to chain:", chainId);
});

対応メソッド

メソッド 対応
eth_requestAccounts ✓
eth_accounts ✓
eth_sendTransaction ✓
eth_signTransaction ✓
personal_sign ✓
eth_signTypedData_v4 ✓
eth_getBalance ✓、ステルス向け拡張
eth_call ✓、ステルス向け拡張
wallet_switchEthereumChain ✓
wallet_addEthereumChain ✓
wallet_getCapabilities ✓、EIP-5792
wallet_sendCalls ✓、EIP-5792
wallet_getCallsStatus ✓、EIP-5792

EIP-5792 のバッチ呼び出し

バッチ取引や補助資金などの高度な機能には wallet_sendCalls を使います。バッチトランザクションを参照してください。