Links
Comment on page

Create a wallet

Onboard your user with a few lines of code

Install

npm i @cometh/connect-sdk

Init the Cometh Connect SDK

To begin with, you'll have to create an instance of the cometh wallet using the sdk, specifying the needed variables (network, apiKey, rpcurl...).
You can name the passkey created by your user using the passkeyName parameter in the ConnectAdaptor class.
TS
Unity
import { ComethWallet, ConnectAdaptor, SupportedNetworks} from "@cometh/connect-sdk";
const walletAdaptor = new ConnectAdaptor({
chainId: SupportedNetworks.POLYGON,
apiKey,
passkeyName:YOUR_PASSKEY_NAME
});
const wallet = new ComethWallet({
authAdapter: walletAdaptor,
apiKey,
rpcUrl: RPC_URL
});
[SerializeField] private ConnectAdaptor authAdaptor;
private ComethWallet _wallet;
private void Start()
{
_wallet = new ComethWallet(authAdapter, API_KEY );
}

Create a new wallet

When your user doesn't already have a wallet, create a new one by calling the connect method without any parameter.
TS
Unity
await wallet.connect();
await _wallet.Connect()
You'll be prompted to create a passKey for your current domain. Depending on the user's device, the UX might be different.
Thanks to these credentials, your wallet address will be predicted and can already be used to receive funds.
However, note that at this point the wallet has not been created onchain yet: the Safe is deployed on the first transaction of the wallet.
To get the address of the wallet created, you'll just have to call:
TS
Unity
wallet.getAddress();
_wallet.GetAddress()
You must store the wallet address of your user. Not saving this address will prevent your user from accessing the wallet it in the future.
It is recommended to store the wallet address in your backend, linked to your user. For a quick demo or Proof of Concept (POC), you may use local storage.

Connect to an existing Connect wallet

When you already have created your user's wallet through Cometh Connect, just pass the wallet address to the connect method in order to instantiate it.
TS
Unity
await wallet.connect(WALLET_ADDRESS);
await _wallet.Connect(WALLET_ADDRESS)
Once your wallet is connected, the user will be prompted to use biometrics when executing a transaction.
Last modified 5d ago