Getting started
Estimated time: 3min
Last updated
Estimated time: 3min
Last updated
You want to try cometh connect ? Request your access to the dashboard
In this tutorial, we'll create a smart wallet and execute a transaction to increment a counter smart contract, using Cometh Connect.
To use Cometh Connect, the first step is to get your api keys at https://app.cometh.io. If this is your first time using Cometh Connect, please reach out so we can set you up with a Connect account and apiKey.
Once you validate the email registration, you'll have access to that panel:
By choosing Connect, you'll be able to create your first Cometh Connect project. For this tutorial, we will create a project on the Mumbai network.
You will then have access to your dashboard.
On your dashboard, you can click on the apiKey button to access all your project's credentials.
You now have your project API key, congrats ! It will be used in your front-end to authenticate public API calls.
Going back to the apiKey button, by clicking on the getting started button you'll be able to download the tutorial repository and start trying it out !
You can then install packages and start the project:
You can now go and test the demo live, here is what you should be able to do:
Most of the logic is in the file /src/app/modules/wallet/hooks/useWalletAuth.tsx, inside the connect method.
First, we initialize the ConnectAdaptor and the ComethWallet:
The ConnectAdaptor is an authentication adaptor that manages the signer of the smart wallet.
The ComethWallet is a way to access the user's smart wallet features
The next step is to verify if the user is already associated with a smart wallet or not.
For the purpose of this demo, we store the smart wallet address of the connected user in local storage.
For a production use case, you must store the wallet address for your user. This should be done in your backend using your preferred Web 2 authentication system. Not saving this address will prevent your user from accessing it in the future.
In the case of an existing user, we call connect with the wallet address: connect(localStorageAddress). The signer has already been created and stored in the secure enclave of the device. Every transaction or message will be signed by this signer.
In the case of a new user, we call the method connect() with no parameter. It will create a new signer and register the wallet in our system. The wallet is not yet deployed, it will be at the first transaction.
We will interact with a simple contract that just increments a counter. We already deployed a test instance for this tutorial on the Mumbai network.
The ABI of the contract is available in /src/app/modules/contract/counterABI.json
We will encapsulate the ComethWallet inside a ComethProvider that can be used as an Ethers V5 Provider for Contracts following EIP-1193.
You are now ready to call methods on this contract using the user's Cometh wallet.
In the file /src/app/components/Transaction.tsx, we call the method count of the contract and wait for the transaction to be mined.
All transactions to our instance of the count test contract are sponsored. Consequently, your users do not require gas to call this contract. You can lean more about this in the "Send transaction" section.