Embed & Integrate
The Silk SDK is designed for ease of use by both seasoned Web3 devs and those new to self-custody wallets and cryptography.
Install
Use
For New Devs
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.
For Web3 Devs
Know how to use windows.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.
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 silk
object as the provider and you are good to go.
Examples
Silk Demo App
We created a demo app that showcases all of Silk's functionality, so you can easily see how these methods behave. Go to our demo-app repository to see and copy the source code or clone the repo to run the app locally.
Silk + Next.js + Viem
Check out the repo below for this template app using Silk and Viem:
Silk + Next.js + Wagmi
This app created by Axé DAO is an example of using Silk wrapped into a Wagmi Connector. The connector code below is going to be shipped with the Silk SDK in the future.
Example wagmi config with Silk Connector
This is the preferred setup, if you want to embed Silk into your app and simply rely on wagmi hooks for all blockchain interaction. Note, however, that the connector is a standard wagmi interface and does not expose the Silk instance and its added features like Request Email or Request SBT. To access these you can instantiate Silk anywhere in your app as a secondary instance using the initSilk
function described above.
Example: ConnectButton with wagmi's useConnect
hook