Send transactions

Sending Web3 transactions has never been easier

Considering that the authentication part is done, you can start to send transactions. You'll just need to create the transaction and send it to the SDK.

Depending on the UX you want to provide, there are different ways of sending transactions.

Send a single transaction

You can build a transaction object containing the targeted contract address, the value of the transaction, and the associated data in the transaction. This payload can be passed to the sendTransaction method of the SDK. A promise is returned by the method to wait for the validation of the transaction.

If this is the first transaction of the wallet, this sendTransaction will automatically be converted to a multi-call doing 2 transactions in one: deploy the Safe smart wallet and send the transaction

const txParams = {
   to: recipient,
   value: "0x00",
   data: "0x",
 };
      
 
 const tx = await wallet.sendTransaction(txParams);
 const txPending = await provider.getTransaction(tx.safeTxHash); 
 const txReceipt = await txPending.wait();

The user will have to sign before the transaction is sent.

Send a Gasless transaction

To enable that feature, please contact us by planning a meeting

With Cometh Connect, you can pay the transaction gas fees of your users. You will need to add the contract address of your transaction as a sponsored address for your project. Remember, the contract address corresponds to the "to" field of your transaction.

Here is the API route to create the sponsored address:

After doing so, you'll be able to send gasless transactions.

Send transactions batches

With Cometh Connect, you can execute multiple actions in the same transaction. To do so you can call the sendBatchTransactions method.

const txParams = [{
   to: targetAddress1,
   value: "0x00",
   data: "0x",
 }, {
   to: targetAddress2,
   value: "0x00",
   data: "0x",
 }];
      
 
 const tx = await wallet.sendBatchTransactions(txParams);
 const txPending = await provider.getTransaction(tx.safeTxHash); 
 const txReceipt = await txPending.wait();

In the same way, you'll then be asked to validate the transaction.

Send a transaction using a contract interface

Another approach would be to use the provider offered by the SDK. You will need to instantiate the ComethProvider ( an Ethereum provider following EIP-1193 ), using the ComethWallet. You can then use your contract interface to directly call the contract methods. Checkout our Getting started for more details.

import {
  ComethWallet,
  ConnectAdaptor,
  ComethProvider,
  SupportedNetworks
} from '@cometh/connect-sdk'

const walletAdaptor = new ConnectAdaptor({
  chainId: YOUR_CHAIN_ID,
  apiKey: API_KEY
})

const wallet = new ComethWallet({
  authAdapter: walletAdaptor,
  apiKey: API_KEY,
  rpcUrl: RPC_URL
})

const provider = new ComethProvider(wallet)

const nftContract = new ethers.Contract(
  NFT_CONTRACT_ADDRESS,
  nftContractAbi,
  provider.getSigner()
)

const tx = await nftContract.count()
const txReceipt = await tx.wait()

Last updated