The Silk SDK is designed for ease of use by both seasoned Web3 devs and those new to self-custody wallets and cryptography.
1. Install
npm i @silk-wallet/silk-wallet-sdk
2. Use
Just getting started with Web3 development?
You can easily embed Silk to your site following standard practices that minimizes bugs or performance issues.
Silk exposes an EIP-1193-compliant interface, so you can use it just as you would use MetaMask, one of the most common Web3 wallet services. The only difference is that Silk must be initialized.
The following code initializes Silk, presents the login modal to the user, and gets the user's wallet addresses.
import { initSilk } from"@silk-wallet/silk-wallet-sdk"// Initialize Silkconstsilk=initSilk()// Open the Silk login modal. silk.login() will throw if the user does not log intry {awaitsilk.login()} catch (error) {console.error(error)}// Optional: Get the user's wallet addressesconstaccounts=awaitsilk.request({ method:'eth_requestAccounts' })
If you want to customize this login flow with additional wallet options for web3-native users, you may choose to use the loginSelector method instead of the login method. This will let you set the options if a user chooses to sign in with a web3 wallet instead. See the Methods section for more details on how to do so.
Know how to use window.ethereum and wagmi?
If you have a codebase that already uses window.ethereum or wagmi, you can still integrate Silk in a couple lines.
First, you need to initialize Silk and have the user login (as above). Then assign silk to window.ethereum.
If you are using wagmi, Silk will work with the injected connector. Just assign silk to window.ethereum, have the user log in, and then use the wagmi hooks as you would with any other wallet.
import { initSilk } from"@silk-wallet/silk-wallet-sdk"// Initialize Silkconstsilk=initSilk()window.ethereum = silk// wagmi's InjectedConnector will now connect to the Silk provider.// Remember to have the user log in. If the user does not log in,// calls to window.ethereum.request() will error out.// silk.login() will throw if the user does not log in.try {awaitwindow.ethereum.login()} catch (error) {console.log(error)}
If you want to give the user other wallet options in the Silk signup screen, use the loginSelector method instead of the login method. See the Methods section for details.
Once users have logged in, you can use Silk as a Provider object with libraries such as viem, ethers, wagmi, or any other that supports EIP-1193 Providers. Simply pass the silkobject as the provider and you are good to go.