Connections
The three methods that manage the accounts an app is connected to: connect with capabilities, disconnect, and add a sub-account. They follow two ERCs that are still drafts.
| Method | JSON-RPC | Returns | Description |
|---|---|---|---|
connect |
wallet_connect |
{ accounts } |
Connects accounts and asks for capabilities in the same prompt (ERC-7846). |
disconnect |
wallet_disconnect |
void |
Disconnects the app’s accounts (ERC-7846). |
addSubAccount |
wallet_addSubAccount |
SubAccount |
Has the wallet create or track an account that its main account owns (ERC-7895). |
connect and addSubAccount take one object whose version is the version of the method,
"1". Each method returns an
Effect<…, Method.Error, Transport>.
To connect accounts and nothing else, use
Wallet.requestAccounts.
connect
Section titled “connect”Connects accounts and, in the same prompt, asks for capabilities such as signing in (ERC-7846, a draft).
import { Effect } from "effect";import { Wallet } from "@ethect/core/rpc";
const signedIn = Effect.gen(function* () { const { accounts } = yield* Wallet.connect({ version: "1", capabilities: { signInWithEthereum: { nonce: "12345678", chainId: "0x1" }, }, }); // the message the wallet built, and its signature return accounts.at(0)?.capabilities?.signInWithEthereum;});- JSON-RPC:
wallet_connect - Returns: an object with
accounts, a list. Each entry has theaddressof a connected account and, when the wallet sends them, thecapabilitiesgranted for it. - A capability is sent as you wrote it. The
chainIdofsignInWithEthereumabove stays the string"0x1".
It takes one object.
| Parameter | Type | Description |
|---|---|---|
version |
string |
the version of the method, "1" |
capabilities |
WalletCapabilities (optional) |
the capabilities to ask for, by name |
disconnect
Section titled “disconnect”Disconnects the app’s accounts and revokes what connect granted (ERC-7846, a
draft).
import { Effect } from "effect";import { Wallet } from "@ethect/core/rpc";
const signOut = Effect.gen(function* () { yield* Wallet.disconnect(); return "disconnected";});- JSON-RPC:
wallet_disconnect - Parameters: none.
- Returns: nothing. Whatever the wallet answers is ignored, and the effect succeeds with
void.
addSubAccount
Section titled “addSubAccount”Has the wallet create or track an account that its main account owns (ERC-7895, a draft).
import { Effect } from "effect";import { Wallet } from "@ethect/core/rpc";
const subAccount = Effect.gen(function* () { const { address } = yield* Wallet.addSubAccount({ version: "1", account: { type: "create", // a public key of the app, to sign for the new account keys: [{ type: "webauthn-p256", publicKey: `0x${"04".repeat(64)}` }], }, }); return address;});- JSON-RPC:
wallet_addSubAccount - Returns: a
SubAccount.SubAccount: theaddressof the account and, where the wallet knows how to deploy it,factoryandfactoryData.
It takes one object.
| Parameter | Type | Description |
|---|---|---|
version |
string |
the version of the method, "1" |
account |
SubAccount.Payload |
the account to add, in one of the three shapes below |
The type of account selects its shape.
type |
Other fields | The account |
|---|---|---|
"create" |
keys (optional) |
one for the wallet to create, with the app’s keys as signers if it gives any |
"deployed" |
address, chainId (optional) |
one that is already deployed |
"undeployed" |
address, factory, factoryData, chainId (optional) |
one the wallet can deploy with factory and factoryData |
An account the app created and has not deployed yet goes with what deploys it.
import { type Address, type Hex } from "@ethect/core";import { Wallet } from "@ethect/core/rpc";
const track = ( address: Address.Address, factory: Address.Address, factoryData: Hex.Hex,) => Wallet.addSubAccount({ version: "1", account: { type: "undeployed", address, chainId: 8453, factory, factoryData }, });Behavior
Section titled “Behavior”- Drafts. ERC-7846 and ERC-7895 are not final: their shapes can change, and a wallet may not serve these methods.
- The chain id is a
number. ThechainIdof a sub-account is sent as a hex quantity:8453leaves as"0x2105". - Lowercase addresses. The addresses of the accounts and of
factorydecode to lowercaseAddressvalues. - Not served by a node. anvil 1.9 answers the three methods with the reason
MethodNotFound.