Skip to main content

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.

Example​

const provider = new ExternalWalletProvider(window.ethereum);
await provider.connect();
const signature = await provider.signMessage('Hello');
const signer = provider.getSigner(); // for GatewayWrites, GSwap, ...

Properties​

PropertyModifierTypeDescription
providerTypereadonlyWalletProviderTypeWhether the provider holds a raw key (privateKey) or signs in a wallet (external).

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.


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.


getGalaAddress()​

getGalaAddress(): Promise<string>

The connected account as GalaChain spells it: eth| plus the checksummed digits.

Returns​

Promise<string>

Throws​

GalaSDKError WALLET_NOT_CONNECTED.


getPrivateKey()?​

optional getPrivateKey(): 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.


getSigner()​

getSigner(): GalaChainSigner

The core signer for GalaChain DTOs, bound to the account connected NOW.

Returns​

GalaChainSigner

Throws​

GalaSDKError WALLET_NOT_CONNECTED.


isConnected()​

isConnected(): boolean

True while the provider has an account to sign for.

Returns​

boolean


onAccountChanged()?​

optional onAccountChanged(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​

ParameterType
listener(address) => void

Returns​

The function that stops the calls.

() => void


restore()?​

optional restore(): 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.


signMessage()​

signMessage(message): Promise<string>

Signs message the way personal_sign does (EIP-191).

Parameters​

ParameterType
messagestring

Returns​

Promise<string>

Throws​

GalaSDKError WALLET_NOT_CONNECTED, or SIGNING_FAILED (user_rejected when the person declined).


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​

ParameterType
domainTypedDataDomain
typesRecord<string, TypedDataField[]>
valueRecord<string, unknown>

Returns​

Promise<string>

Throws​

GalaSDKError WALLET_NOT_CONNECTED, or SIGNING_FAILED.