providers/classes/GalaWalletProvider.md
Gala Wallet as a wallet provider.
Example
const provider = new GalaWalletProvider(window.gala);
const address = await provider.connect();
const signature = await provider.signMessage('Hello');
Extends
WalletConnection<GalaWalletExtension>
wallet connection gala extension
Implements
wallet provider
Constructors
Constructor
new GalaWalletProvider(
provider):GalaWalletProvider
Parameters
| Parameter | Type | Description |
|---|---|---|
provider | GalaWalletExtension | Gala Wallet (window.gala, or its EIP-6963 announcement's provider). |
Returns
GalaWalletProvider
Throws
GalaSDKError INVALID_WALLET_PROVIDER_CONFIG when no provider is given.
Overrides
WalletConnection<GalaWalletExtension>.constructor
gala wallet provider extension 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>
Forgets the account and ends the wallet's session (disconnect, where it offers one).
Returns
Promise<void>
Implementation of
wallet 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():
GalaWalletExtension
The wallet object the provider talks to.
Returns
Inherited from
WalletConnection.getProvider
get provider gala wallet extension connection
getSigner()
getSigner(
options?):GalaChainSigner
The core GalaWalletSigner for GalaChain DTOs, bound to the account connected now and signing through this provider's wallet object.
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | { scheme?: GalaWalletScheme; } | { scheme: 'personal-sign' } opts into Gala Wallet's personal-sign scheme (see GalaWalletSigner); the default is native signing. |
options.scheme? | GalaWalletScheme | - |
Returns
Throws
GalaSDKError WALLET_NOT_CONNECTED.
Implementation of
get signer gala chain wallet scheme 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, after switching Gala Wallet to the connected account.
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, after switching Gala Wallet to the
connected account.
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