postMessage
.
It securely interacts with the Turnkey API. Reference the popup-wallet-demo
’s @/apps/wallet
provides a concrete example.
EIP-1193 Provider: A JavaScript class implementing the EIP-1193 standard.
It acts as the intermediary between the dApp and the popup embedded wallet. Reference the popup-wallet-demo
’s @/apps/dapp/lib/eip1193-provider.ts
provides a concrete example.
Wagmi Connector: A custom connector built using Wagmi’s createConnector
utility. It wraps our EIP-1193 provider, making the wallet compatible with the Wagmi ecosystem. Reference the popup-wallet-demo
’s @/apps/dapp/lib/connector.ts
and @/apps/dapp/lib/wagmi.ts
provide concrete examples.
connect
method on your Wagmi connector.provider.request({ method: 'eth_requestAccounts' })
, which opens your Embedded Wallet pop-up.chainId
to the provider via postMessage
.eth_requestAccounts
, and the connector returns the account(s) and chainId
to the dApp.eth_sendTransaction
):
useSendTransaction
) which triggers a request.eth_sendTransaction
request to your connector.postMessage
.postMessage
.eth_blockNumber
):
eth_blockNumber
request to your connector.eth_requestAccounts
.
<CodeGroup>
component so you can copy either file.
https://<your-wallet-host>/?request=<encoded-json-rpc>
.request
query parameter.AuthButton
performs your authentication logic (Turnkey passkey, email-magic-link, etc.).postMessage
back to the opener containing the selected account(s) and chainId
.AuthButton
(or wherever your auth logic resolves) send a message with the newly authenticated account:
This keeps the wallet UI decoupled from the provider implementation—any parent window that understands the ETH_ACCOUNTS
message can integrate.
eip1193-provider.ts
in your dApp project. For the connection flow we only need to implement eth_requestAccounts
and eth_accounts
:
postMessage
containing ETH_ACCOUNTS
.eth_requestAccounts
promise and lets Wagmi continue.connect
method to use the provider you just built. The full version from popup-wallet-demo
already includes this; here’s the shortened core for reference:
localhost:3001
.useSendTransaction
, useSignMessage
, and related Wagmi hooks.
popupRequest
is the existing helper that opens/targets the window and resolves the corresponding RPC_RESPONSE
.
eth_requestAccounts
).eth_signTransaction
/ eth_sendTransaction
).personal_sign
/ eth_sign
).
From here you can layer additional EIP-1193 methods (chain switching, asset watch, etc.) as needed.
id
per RPC call, store promises by id
, include it in every postMessage
so concurrent requests cannot collide.accounts
and chainId
in localStorage
and return them on subsequent eth_accounts
calls without re-authenticating.wallet_switchEthereumChain
, update store.chainId
, and emit chainChanged
.event.origin
, allow-list dApp domains, move hard-coded URLs (localhost:3001
, RPC endpoints) into environment variables.wallet_watchAsset
, eth_addEthereumChain
, etc., if dApps require them.
Addressing these items will bring the prototype to production-ready quality without altering the core architecture documented above.