Smart Wallet
This page is a full reference, explaining how to use Smart Wallet with the Wallet SDK to connect a smart wallet to your app.
For a complete overview of Smart Wallets, visit the Smart Wallet SDK documentation.
Let your users connect to any Smart Wallet.
A Smart Wallet is a wallet that is controlled by a smart contract following the ERC-4337 specification.
Usage
To connect to a smart wallet, a personal wallet (acting as the key to the smart wallet) must first be connected.
import { LocalWallet, SmartWallet } from "@thirdweb-dev/wallets";
import { Goerli } from "@thirdweb-dev/chains";
// First, connect the personal wallet, which can be any wallet (metamask, walletconnect, etc.)
// Here we're just generating a new local wallet which can be saved later
const personalWallet = new LocalWallet();
await personalWallet.generate();
// Setup the Smart Wallet configuration
const config: SmartWalletConfig = {
chain: Goerli, // the chain where your smart wallet will be or is deployed
factoryAddress: "{{factory_address}}", // your own deployed account factory address
clientId: "YOUR_CLIENT_ID", // Use client id if using on the client side, get it from dashboard settings
secretKey: "YOUR_SECRET_KEY", // Use secret key if using on the server, get it from dashboard settings
gasless: true, // enable or disable gasless transactions
};
// Then, connect the Smart wallet
const wallet = new SmartWallet(config);
await wallet.connect({
personalWallet,
});
// You can then use this wallet to perform transactions via the SDK
const sdk = await ThirdwebSDK.fromWallet(wallet, Goerli);
Configuration
Here's the full configuration object you can pass when instantiating the SmartWallet
class.
Mandatory properties
chain
factoryAddress
clientId or secretKey (recommended)
gasless
Optional properties
clientId or secretKey (optional)
factoryInfo
accountInfo
bundlerUrl
paymasterUrl
paymasterAPI
entryPointAddress
chains
dappMetadata
walletId
enableConnectApp
wcVersion
walletConnectV2ProjectId
walletConnectV2RelayUrl
walletConnectWalletMetadata
wcStorage
Methods
Inherits all the public methods from the AbstractClientWallet
class.
connect
Connect the smart wallet to your app using a personal wallet.
This personal wallet must be connected before connecting to a Smart wallet.
import { CoinbaseWallet, SmartWallet } from "@thirdweb-dev/wallets";
import { Ethereum } from "@thirdweb-dev/chains";
// First, connect the personal wallet
const personalWallet = new CoinbaseWallet();
const personalWalletAddress = await personalWallet.connect();
// Then, connect the Smart wallet
const smartWallet = new SmartWallet(config);
const smartWalletAddress = await smartWallet.connect({
personalWallet,
});
Configuration
execute
Execute a single transaction as the connected Smart Wallet.
// first, connect the Smart wallet
const wallet = new SmartWallet(config);
await wallet.connect({
personalWallet,
});
// Then you can execute transactions directly
const transaction = prepareTransaction();
await wallet.execute(transaction);
Configuration
executeBatch
Execute multiple transactions as the connected Smart Wallet at once, only requiring one signature from the personal wallet.
// first, connect the Smart wallet
const wallet = new SmartWallet(config);
await wallet.connect({
personalWallet,
});
// Then you can execute multiple transactions at once
const transactions = [
prepareTransaction1(),
prepareTransaction2(),
prepareTransaction3(),
];
await wallet.executeBatch(transactions);
Configuration
createSessionKey
Create and add a session key to the Smart Wallet with specific permissions.
// first, connect the Smart wallet
const wallet = new SmartWallet(config);
await wallet.connect({
personalWallet,
});
// Then you can add session keys with permissions
await wallet.createSessionKey(
"0x...", // the session key address
{
approvedCallTargets: ["0x..."], // the addresses of contracts that the session key can call
nativeTokenLimitPerTransaction: 0.1, // the maximum amount of native token (in ETH) that the session key can spend per transaction
startDate: new Date(), // the date when the session key becomes active
expirationDate = new Date(Date.now() + 24 * 60 * 60 * 1000); // the date when the session key expires
}
);
Configuration
revokeSessionKey
Revoke a session key from the Smart Wallet.
// first, connect the Smart wallet
const wallet = new SmartWallet(config);
await wallet.connect({
personalWallet,
});
// Then you can revoke session keys
await wallet.revokeSessionKey(
"0x...", // the session key address
);
Configuration
isDeployed
Check if the Smart Wallet is deployed onchain.
// first, connect the Smart wallet
const wallet = new SmartWallet(config);
await wallet.connect({
personalWallet,
});
const isDeployed = await wallet.isDeployed();
console.log("Smart Wallet deployed:", isDeployed); // true or false
deploy
Force deploy the Smart Wallet onchain. Will throw if already deployed.
// first, connect the Smart wallet
const wallet = new SmartWallet(config);
await wallet.connect({
personalWallet,
});
const tx = await wallet.deploy();
console.log("Smart Wallet deployed:", tx); // the transaction receipt
deployIfNeeded
Force deploy the Smart Wallet onchain. If already deployed, will do nothing.
// first, connect the Smart wallet
const wallet = new SmartWallet(config);
await wallet.connect({
personalWallet,
});
await wallet.deployIfNeeded();
getPersonalWallet
Get the personal wallet that is connected to the Smart Wallet.
// first, connect the Smart wallet
const wallet = new SmartWallet(config);
await wallet.connect({
personalWallet,
});
const personalWallet = wallet.getPersonalWallet();