providers/interfaces/WalletProvider.md
One wallet, however it signs: PrivateKeyProvider, ExternalWalletProvider (EIP-1193 browser wallets) or GalaWalletProvider.
signMessage / signTypedData sign ARBITRARY messages and typed data (logins, permits);
getSigner gives the core GalaChainSigner for GalaChain DTOs, bound to the account the
provider is connected to when it is called. After the account changes, get a new signer: a
signer keeps the identity it was made for, so a write never silently signs as someone else.
sign message typed data get signer
Example
const provider = new ExternalWalletProvider(window.ethereum);
await provider.connect();
const signature = await provider.signMessage('Hello');
const signer = provider.getSigner(); // for GatewayWrites, GSwap, ...
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
providerType | readonly | WalletProviderType | Whether the provider holds a raw key (privateKey) or signs in a wallet (external). |
provider type wallet private key
Methods
connect()
connect():
Promise<string>
Asks the wallet for account access (a private-key provider is always ready).
Returns
Promise<string>
The connected account (0x, checksummed).
Throws
GalaSDKError WALLET_CONNECTION_FAILED.
wallet connection failed
disconnect()
disconnect():
Promise<void>
Forgets the account and stops listening to the wallet's events.
Returns
Promise<void>
getAddress()
getAddress():
Promise<string>
The connected account: 0x plus its EIP-55 checksummed digits.
Returns
Promise<string>
Throws
GalaSDKError WALLET_NOT_CONNECTED.
get address wallet not connected
getGalaAddress()
getGalaAddress():
Promise<string>
The connected account as GalaChain spells it: eth| plus the checksummed digits.
Returns
Promise<string>
Throws
GalaSDKError WALLET_NOT_CONNECTED.
get gala address wallet not connected
getPrivateKey()?
optionalgetPrivateKey():Promise<string>
The raw private key (0x plus 64 lower-case hex digits). Only a PrivateKeyProvider
has one.
Returns
Promise<string>
Throws
GalaSDKError PRIVATE_KEY_NOT_ACCESSIBLE for a wallet-backed provider.
get private key not accessible
getSigner()
getSigner():
GalaChainSigner
The core signer for GalaChain DTOs, bound to the account connected NOW.
Returns
Throws
GalaSDKError WALLET_NOT_CONNECTED.
get signer gala chain wallet not connected
isConnected()
isConnected():
boolean
True while the provider has an account to sign for.
Returns
boolean
is connected
onAccountChanged()?
optionalonAccountChanged(listener): () =>void
Calls listener with the new account whenever it changes (the wallet switched accounts, or
connect()), and with null once disconnected. Every provider in this package has it; a
custom provider may leave it out.
Parameters
| Parameter | Type |
|---|---|
listener | (address) => void |
Returns
The function that stops the calls.
() => void
on account changed
restore()?
optionalrestore():Promise<string|null>
Reconnects to the account the wallet already lets this site use, without a wallet prompt
(eth_accounts, never eth_requestAccounts). Every wallet-backed provider in this package has
it; a private-key provider and a custom provider may leave it out. Never throws.
Returns
Promise<string | null>
The connected account (0x, checksummed), or null when the wallet reports none.
eth accounts request
signMessage()
signMessage(
message):Promise<string>
Signs message the way personal_sign does (EIP-191).
Parameters
| Parameter | Type |
|---|---|
message | string |
Returns
Promise<string>
Throws
GalaSDKError WALLET_NOT_CONNECTED, or SIGNING_FAILED (user_rejected when the
person declined).
sign message personal wallet not connected signing failed user rejected
signTypedData()
signTypedData(
domain,types,value):Promise<string>
Signs EIP-712 typed data (eth_signTypedData_v4). types excludes EIP712Domain; the primary
type is the FIRST key of types.
Parameters
| Parameter | Type |
|---|---|
domain | TypedDataDomain |
types | Record<string, TypedDataField[]> |
value | Record<string, unknown> |
Returns
Promise<string>
Throws
GalaSDKError WALLET_NOT_CONNECTED, or SIGNING_FAILED.
sign typed data eth v4 eip712 domain field wallet not connected signing failed