Skip to main content

Class: ExternalWalletProvider

GalaChain core SDK 1.0.0-rc.8


GalaChain core SDK 1.0.0-rc.8 / providers / ExternalWalletProvider

Class: ExternalWalletProvider

Defined in: packages/gala-core-sdk/dist/providers.d.ts:320

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​

Implements​

Constructors​

Constructor​

new ExternalWalletProvider(provider): ExternalWalletProvider

Defined in: packages/gala-core-sdk/dist/providers.d.ts:326

Parameters​

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

Properties​

providerType​

readonly providerType: WalletProviderType

Defined in: packages/gala-core-sdk/dist/providers.d.ts:321

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

Implementation of​

WalletProvider.providerType

Methods​

connect()​

connect(): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:237

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​

WalletProvider.connect

Inherited from​

WalletConnection.connect


disconnect()​

disconnect(): Promise<void>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:333

Revokes the account permission where the wallet supports it (wallet_revokePermissions) and forgets the account.

Returns​

Promise<void>

Implementation of​

WalletProvider.disconnect


getAddress()​

getAddress(): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:262

The connected account (0x, checksummed).

Returns​

Promise<string>

Throws​

GalaSDKError WALLET_NOT_CONNECTED.

Implementation of​

WalletProvider.getAddress

Inherited from​

WalletConnection.getAddress


getGalaAddress()​

getGalaAddress(): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:268

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

Returns​

Promise<string>

Throws​

GalaSDKError WALLET_NOT_CONNECTED.

Implementation of​

WalletProvider.getGalaAddress

Inherited from​

WalletConnection.getGalaAddress


getPrivateKey()​

getPrivateKey(): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:274

A wallet-backed provider never holds the key.

Returns​

Promise<string>

Throws​

GalaSDKError PRIVATE_KEY_NOT_ACCESSIBLE, always.

Implementation of​

WalletProvider.getPrivateKey

Inherited from​

WalletConnection.getPrivateKey


getProvider()​

getProvider(): Eip1193Provider

Defined in: packages/gala-core-sdk/dist/providers.d.ts:282

The wallet object the provider talks to.

Returns​

Eip1193Provider

Inherited from​

WalletConnection.getProvider


getSigner()​

getSigner(options?): GalaChainSigner

Defined in: packages/gala-core-sdk/dist/providers.d.ts:353

The core BrowserWalletSigner for GalaChain DTOs, bound to the account connected now.

Parameters​

options?​

{ scheme: 'eip712' } signs the EIP-712-capable DEX methods with eth_signTypedData_v4 (resolving a registered client| alias); the default is personal_sign.

scheme?​

"personal-sign" | "eip712"

Returns​

GalaChainSigner

Throws​

GalaSDKError WALLET_NOT_CONNECTED.

Implementation of​

WalletProvider.getSigner


isConnected()​

isConnected(): boolean

Defined in: packages/gala-core-sdk/dist/providers.d.ts:256

True while the provider has an account to sign for.

Returns​

boolean

Implementation of​

WalletProvider.isConnected

Inherited from​

WalletConnection.isConnected


onAccountChanged()​

onAccountChanged(listener): () => void

Defined in: packages/gala-core-sdk/dist/providers.d.ts:280

Calls listener with the new account whenever it changes (null once disconnected).

Parameters​

listener​

AccountListener

Returns​

The function that stops the calls.

() => void

Implementation of​

WalletProvider.onAccountChanged

Inherited from​

WalletConnection.onAccountChanged


release()​

release(): void

Defined in: packages/gala-core-sdk/dist/providers.d.ts:289

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


restore()​

restore(): Promise<string | null>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:254

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​

WalletProvider.restore

Inherited from​

WalletConnection.restore


signMessage()​

signMessage(message): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:339

Signs message with personal_sign (the wallet applies EIP-191).

Parameters​

message​

string

Returns​

Promise<string>

Throws​

GalaSDKError WALLET_NOT_CONNECTED, SIGNING_FAILED, INVALID_SIGNATURE.

Implementation of​

WalletProvider.signMessage


signTypedData()​

signTypedData(domain, types, value): Promise<string>

Defined in: packages/gala-core-sdk/dist/providers.d.ts:345

Signs EIP-712 typed data with eth_signTypedData_v4.

Parameters​

domain​

TypedDataDomain

types​

Record<string, TypedDataField[]>

value​

Record<string, unknown>

Returns​

Promise<string>

Throws​

GalaSDKError WALLET_NOT_CONNECTED, SIGNING_FAILED, INVALID_SIGNATURE.

Implementation of​

WalletProvider.signTypedData