SafeWallet
Wallet interface to connect Safe wallet .
To connect to a safe wallet, a personal wallet must first be connected.
import { CoinbaseWallet, SafeWallet } from "@thirdweb-dev/wallets";import { Ethereum } from "@thirdweb-dev/chains"; // First, connect the personal walletconst personalWallet = new CoinbaseWallet();await personalWallet.connect(); // Then, connect the Safe walletconst wallet = new SafeWallet();await wallet.connect({ personalWallet: personalWallet, chain: Ethereum, safeAddress: "{{contract_address}}",});
object,> {}
Create a SafeWallet instance.
function constructor(options?: { analytics?: "enabled" | "disabled"; chains?: Array<Chain>; clientId?: string; walletId?: string;
The options object includes the following properties:
Provide clientId to use the thirdweb RPCs for given chains
You can create a client ID for your application from thirdweb dashboard .
Provide an array of chains you want to support.
Must be an array of Chain objects, from the @thirdweb-dev/chains package.
Defaults to our default chains .
Information about your app that the wallet will display when your app tries to connect to it.
Must be an object containing name , url , description and logoUrl properties.
import { SafeWallet } from "@thirdweb-dev/wallets"; const walletWithOptions = new SafeWallet({ dappMetadata: { name: "thirdweb powered dApp", url: "https://thirdweb.com", description: "thirdweb powered dApp", logoUrl: "https://thirdweb.com/favicon.ico", },});
let options: { analytics?: "enabled" | "disabled"; chains?: Array<Chain>; clientId?: string; walletId?: string;};
Auto connect the wallet if it was previously connected.
function autoConnect(): Promise<string>;
Connect Safe wallet
import { CoinbaseWallet, SafeWallet } from "@thirdweb-dev/wallets";import { Ethereum } from "@thirdweb-dev/chains"; // First, connect the personal walletconst personalWallet = new CoinbaseWallet();await personalWallet.connect(); // Then, connect the Safe walletconst wallet = new SafeWallet();await wallet.connect({ personalWallet: personalWallet, // Wallet that can sign transactions on the Safe chain: Ethereum, // Chain that the Safe is on safeAddress: "{{contract_address}}", // Smart contract address of the Safe});
The instance of a personal wallet that can sign transactions on the Safe.
Must be of type EVMWallet such as CoinbaseWallet or MetamaskWallet .
The chain that the Safe smart contract is deployed to.
Must be a Chain object, from the @thirdweb-dev/chains package.
Smart contract address of the Safe wallet.
Must be a string .
function connect(): Promise<string>;
The connectOptions object includes the following properties:
Get the personal wallet that is connected to the Safe wallet.
AbstractClientWallet.addListenerfunction addListener( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.disconnectDisconnect the wallet
function disconnect(): Promise<void>;
AbstractClientWallet.emitCalls each of the listeners registered for a given event.
function emit( event: T,): boolean;
AbstractClientWallet.eventNamesReturn an array listing the events for which the emitter has registered listeners.
AbstractClientWallet.getAddressReturns the account address of the connected wallet
function getAddress(): Promise<string>;
AbstractClientWallet.getBalanceReturns the balance of the connected wallet for the specified token address. If no token address is specified, it returns the balance of the native token
function getBalance( tokenAddress: string,): Promise<{ decimals: number; displayValue: string; name: string; symbol: string; value: BigNumber;}>;
AbstractClientWallet.getChainIdReturns the chain id of the network that the wallet is connected to
function getChainId(): Promise<number>;
AbstractClientWallet.getSignerGet ethers Signer object of the connected wallet
function getSigner(): Promise<Signer>;
AbstractClientWallet.listenerCountReturn the number of listeners listening to a given event.
AbstractClientWallet.listenersReturn the listeners registered for a given event.
function listeners( event: T,): Array< ( ) => void>;
let returnType: Array< ( ) => void>;
AbstractClientWallet.offfunction off( event: T, fn?: ( ) => void, context?: any, once?: boolean,): this;
let fn: () => void;
AbstractClientWallet.onAdd a listener for a given event.
function on( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.onceAdd a one-time listener for a given event.
function once( event: T, fn: ( ) => void, context?: any,): this;
let fn: () => void;
AbstractClientWallet.removeListenerRemove the listeners of a given event.
function removeListener( event: T, fn?: ( ) => void, context?: any, once?: boolean,): this;
let fn: () => void;
AbstractClientWallet.signMessageSign a message with the connected wallet and return the signature
function signMessage(message: string | Bytes): Promise<string>;
AbstractClientWallet.switchChainSwitch to different Network/Blockchain in the connected wallet
function switchChain(chainId: number): Promise<void>;
AbstractClientWallet.transferTransfers some amount of tokens to the specified address
function transfer( to: string, amount: string | number, currencyAddress: string,): Promise<Omit<TransactionResultWithMetadata<unknown>, "data">>;
AbstractClientWallet.updateChainsUpdate the chains supported by the wallet. This is useful if wallet was initialized with some chains and this needs to be updated without re-initializing the wallet
function updateChains(chains: Array<Chain>): Promise<void>;
AbstractClientWallet.verifySignature Verify the signature of a message. It returns true if the signature is valid, false otherwise
function verifySignature( message: string, signature: string, address: string, _chainId?: number,): Promise<boolean>;
let walletId: string;
let prefixed: string | boolean;