StarknetKit is a development SDK that enables developers to effortlessly build and connect their dApps to Starknet with Starknet.js.
Some of the amazing features that come with the StarknetKit SDK are:
- Easy implementation: No matter your skill level, you shouldn’t have trouble with integrating StarknetKit. This can be done with one line of code, and there’s detailed documentation to help you get started.
- Flexible customizations: With StarknetKit unlike the existing get-starknet, you have the ability to choose which wallets you want to show to dApps and the order in which you show them.
- Easily add custom connectors: one of the biggest advantages StarknetKit presents is the ability to easily add custom connectors to the existing package thanks to the modular structure we’ve implemented (inspired by starknet-react).
Integrating the StarknetKit SDK in your dApp
We've made it easy for you to integrate this SDK. In this section, I’m going to walk you through integrating the StarknetKit SDK in your dApps.
To get started, we need to set up a React application. You could do this, by running the create-react-app command:
Having done that, we’d need to install the `starknetkit` SDK. To do this, run the command below:
or for use with npm:
Installing the starknetkit package exposes some important methods for use in your dApps.
For the purpose of this guide, we are going to import just two major ones: connect and disconnect
Establishing a connection
To establish a wallet connection, we need to call the connect method which was earlier imported like this:
const connection = await connect();
This method exposes some further methods that can be useful to get the connected address, check the status of the connection, etc. Here are a few we’ll be using as we go forward:
- isConnected - This method available after an attempt to establish a connection, can be used to confirm if an account was truly connected.
- selectedAddress - This method can be called to get the wallet address of a connected account.
- account - This method gives us access to the account object. It uses starknet.js AccountInterface and extends the starknet.js Provider.
PS: Remember to import the useState and useEffect Hooks, to avoid compilation errors.
Now we’d write our full function logic for establishing a connection:
First, we call the connect method and save the promise returned to the `connection` variable, then we check if the connection was established, and if yes, we go ahead to initialize the connection , account , and address states from earlier.
NB: the `webWalletUrl` argument is only necessary if you want to include the email login option.
Disconnection Logic
To disconnect an existing connection, simply call the disconnect method from our imports:
Connecting on Reload
Lastly, we might want to check for an existing connection on browser reload, and automatically re-establish our connection if one exists:
Having done all these, we just successfully integrated the StarknetKit SDK into our dApp 🎉.
Integrating StarknetKit with Starknet-react
Starknet-react is an open-source collection of React providers and hooks designed by the Apibara team for Starknet.
Our modular design greatly inspired by starknet-react, ensures you can easily integrate StarknetKit into any existing or new starknet-react project in a few simple steps.
Firstly, we’ll need to install starknet-react dependencies. To do that, simply run:
Then we’ll go ahead to create a starknet-provider component which will contain all our configurations. In here we’ll need to specify the `chains` our dApp exists on, the `provider` we’ll be using for calls, and our `connectors`.
NB: for this guide, we used the default publicProvider(), available with starknet-react, but you can decide to use custom RPCs from providers such as Infura, Alchemy, etc.
Having configured and exported our starknet-provider, we are going to then wrap our app with the provider we just created:
Having done these we should now be able to access starknet-react hooks from any component wrapped by the root provider.
You can refer to the documentation for a more detailed guide.
Conclusion
In conclusion, we’re very excited about StarknetKit and are proud to have launched with AVNU, briqNFT, and StarknetID, we can’t wait to see how it’s adopted by the Starknet community!
If you have any questions, please contact me @0xdarlington, I’d love to help you build on Starknet with Argent.
For more developer resources, follow us across our socials:
Twitter — @argentHq
Engineering Twitter — @argentDeveloper
LinkedIn — @argentHq
Youtube — @argentHQ