providers/classes/ExternalWalletProvider.md
A browser wallet behind EIP-1193.
Example
const provider = new ExternalWalletProvider(window.ethereum);
const address = await provider.connect();
const signature = await provider.signMessage('Hello');
await provider.disconnect();
Extends
WalletConnection<Eip1193Provider>
wallet connection eip1193 provider
Implements
wallet provider
Constructors
Constructor
new ExternalWalletProvider(
provider):ExternalWalletProvider
Parameters
| Parameter | Type | Description |
|---|---|---|
provider | Eip1193Provider | The wallet's EIP-1193 provider (window.ethereum, an EIP-6963 announcement). |
Returns
ExternalWalletProvider
Throws
GalaSDKError INVALID_WALLET_PROVIDER_CONFIG when no provider is given.
Overrides
WalletConnection<Eip1193Provider>.constructor
external wallet provider eip1193 invalid config connection
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 (eth_requestAccounts) and listens to its account and
disconnect events from then on.
Returns
Promise<string>
The connected account (0x, checksummed).
Throws
GalaSDKError WALLET_CONNECTION_FAILED (no_accounts, user_rejected, failed),
WALLET_NOT_CONNECTED (the wallet refused or is disconnected, or disconnect() was called
before the wallet answered).
Implementation of
Inherited from
WalletConnection.connect
eth request accounts wallet connection failed no user rejected not connected provider
disconnect()
disconnect():
Promise<void>
Revokes the account permission where the wallet supports it (wallet_revokePermissions) and
forgets the account.
Returns
Promise<void>
Implementation of
wallet revoke permissions provider
getAddress()
getAddress():
Promise<string>
The connected account (0x, checksummed).
Returns
Promise<string>
Throws
GalaSDKError WALLET_NOT_CONNECTED.
Implementation of
Inherited from
WalletConnection.getAddress
get address wallet not connected provider connection
getGalaAddress()
getGalaAddress():
Promise<string>
The connected account as GalaChain spells it (eth| plus the checksummed digits).
Returns
Promise<string>
Throws
GalaSDKError WALLET_NOT_CONNECTED.
Implementation of
Inherited from
WalletConnection.getGalaAddress
get gala address wallet not connected provider connection
getPrivateKey()
getPrivateKey():
Promise<string>
A wallet-backed provider never holds the key.
Returns
Promise<string>
Throws
GalaSDKError PRIVATE_KEY_NOT_ACCESSIBLE, always.
Implementation of
Inherited from
WalletConnection.getPrivateKey
get private key not accessible wallet provider connection
getProvider()
getProvider():
Eip1193Provider
The wallet object the provider talks to.
Returns
Inherited from
WalletConnection.getProvider
get provider eip1193 wallet connection
getSigner()
getSigner(
options?):GalaChainSigner
The core BrowserWalletSigner for GalaChain DTOs, bound to the account connected now.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | { scheme?: "personal-sign" | "eip712"; } | { scheme: 'eip712' } signs the EIP-712-capable DEX methods with eth_signTypedData_v4 (resolving a registered client| alias); the default is personal_sign. |
options.scheme? | "personal-sign" | "eip712" | - |
Returns
Throws
GalaSDKError WALLET_NOT_CONNECTED.
Implementation of
get signer gala chain eth sign typed data v4 personal wallet not connected provider
isConnected()
isConnected():
boolean
True while the provider has an account to sign for.
Returns
boolean
Implementation of
Inherited from
WalletConnection.isConnected
is connected wallet provider connection
onAccountChanged()
onAccountChanged(
listener): () =>void
Calls listener with the new account whenever it changes (null once disconnected).
Parameters
| Parameter | Type |
|---|---|
listener | AccountListener |
Returns
The function that stops the calls.
() => void
Implementation of
WalletProvider.onAccountChanged
Inherited from
WalletConnection.onAccountChanged
on account changed listener wallet provider connection
release()
release():
void
Retires this provider object WITHOUT asking the wallet to end its session (unlike
disconnect(), which revokes / disconnects in the wallet): it forgets the account and removes
its listeners from the wallet. For code that drops a provider it created, so the wallet keeps
no listener of a provider nobody uses (the React context does it when it switches wallets).
Returns
void
Inherited from
WalletConnection.release
wallet connection
restore()
restore():
Promise<string|null>
Reconnects to the account the wallet already lets this site use, WITHOUT a wallet prompt (for
the page reload after an earlier connect()): asks eth_accounts only, never
eth_requestAccounts. When the wallet reports an account the provider is connected to it and
listens to the wallet's events, exactly as after connect(); otherwise it stays not connected
and holds no listener.
Nothing here throws. The wallet reporting no account, an account that is not an Ethereum
address, or eth_accounts failing all answer null: a silent restore that cannot happen is
not an error, the user connects with connect(). A disconnect(), a wallet event or a
connect() that lands while the wallet is answering wins over the answer (it may be older than
they are); the provider then answers its state at that moment.
Returns
Promise<string | null>
The connected account (0x, checksummed), or null when not connected. Already
connected: the connected account, with no request.
Implementation of
Inherited from
WalletConnection.restore
eth accounts request wallet provider connection
signMessage()
signMessage(
message):Promise<string>
Signs message with personal_sign (the wallet applies EIP-191).
Parameters
| Parameter | Type |
|---|---|
message | string |
Returns
Promise<string>
Throws
GalaSDKError WALLET_NOT_CONNECTED, SIGNING_FAILED, INVALID_SIGNATURE.
Implementation of
sign message personal wallet not connected signing failed invalid signature provider
signTypedData()
signTypedData(
domain,types,value):Promise<string>
Signs EIP-712 typed data with eth_signTypedData_v4.
Parameters
| Parameter | Type |
|---|---|
domain | TypedDataDomain |
types | Record<string, TypedDataField[]> |
value | Record<string, unknown> |
Returns
Promise<string>
Throws
GalaSDKError WALLET_NOT_CONNECTED, SIGNING_FAILED, INVALID_SIGNATURE.
Implementation of
sign typed data eth v4 domain field wallet not connected signing failed invalid signature provider