Coder Social home page Coder Social logo

connect-sdk's Introduction

Connect SDK

Cometh Connect SDK allows developers to onboard their users with a seedless, gasless experience familiar to Web2 using Biometrics and web2 logins.

Account Abstraction (AA) improves transaction user experience by using smart contract wallets as primary accounts.

If you need more information on how to use the SDK check our documentation

Instanciate Wallet

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

const walletAdaptor = new ConnectAdaptor({
  chainId: SupportedNetworks.POLYGON,
  apiKey: API_KEY
})

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

To get an API key please Contact us

Available methods

Create a Wallet

await wallet.connect()

This function create a new wallet and connect to the API.

Get Address

wallet.getAddress()

This function returns the address of the wallet.

Instanciate a Wallet

await wallet.connect(walletAddress)

You can also connect to a previously created wallet. You'll have to provide the wallet address of the previously created wallet.

Logout

await wallet.logout()

This function logs the user out and clears the cache.

Send transaction

const txParams = { to: DESTINATION, value: VALUE, data: DATA }
const tx = await wallet.sendTransaction(txParams)
const txPending = await provider.getTransaction(tx.safeTxHash); 
const txReceipt = await txPending.wait();

This function relays the transaction data to the target address. The transaction fees can be sponsored.

Send Batch transactions

const txParams = [
  { to: DESTINATION, value: VALUE, data: DATA },
  { to: DESTINATION, value: VALUE, data: DATA }
]
const tx = await wallet.sendBatchTransactions(txParams)
const txPending = await provider.getTransaction(tx.safeTxHash); 
const txReceipt = await txPending.wait();

This function relays a batch of transaction data to the targeted addresses. The transaction fees can be sponsored as well.

Sign Message

const signature = await wallet.signMessage('hello')

Sign the given message using the EOA, owner of the smart wallet.

Go further

Interact with contract interface

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

const walletAdaptor = new ConnectAdaptor({
  chainId: SupportedNetworks.POLYGON,
  apiKey: API_KEY,
  passkeyName: passkeyName
})

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()

You can also interact with the interface of a contract, calling directly the contract functions.

Web3Onboard connector

import {
  ConnectAdaptor,
  SupportedNetworks,
  ConnectOnboardConnector
} from '@cometh/connect-sdk'
import injectedModule from '@web3-onboard/injected-wallets'
import Onboard from '@web3-onboard/core'

const walletAdaptor = new ConnectAdaptor({
  chainId: SupportedNetworks.POLYGON,
  apiKey: API_KEY,
  passkeyName: passkeyName
})

const connectOnboardConnector = ConnectOnboardConnector({
  apiKey: API_KEY,
  authAdapter: walletAdaptor,
  rpcUrl: RPC_URL
})

const web3OnboardInstance = Onboard({
  wallets: [injectedModule(), connectOnboardConnector],
  chains: [
    {
      id: ethers.utils.hexlify(DEFAULT_CHAIN_ID),
      token: 'MATIC',
      label: 'Matic Mainnet',
      rpcUrl: 'https://polygon-rpc.com'
    }
  ]
})

You can also incorporate cometh connect to web3Onboard wallet modal solution.

connect-sdk's People

Contributors

yoanslvy avatar fdematos avatar mathieulrl avatar laurentsalou avatar rvkoon avatar shoto290 avatar draym avatar

Stargazers

Crisgarner avatar Dhruv Malik avatar  avatar  avatar Ludovic_Domingues avatar AM avatar Shorn avatar

Watchers

Jérôme Bernard avatar  avatar Arthur Tayrac avatar Vincent Le Gallic avatar  avatar Benjamin Payoux avatar Guillaume Badi avatar Jerome de Tychey avatar Soyeon Kong avatar

connect-sdk's Issues

Module not found: ESM packages (@web3-onboard/common)

Hello,

on my project I have an error when I use @cometh/connect-sdk on the server side. I've created a project in Nextjs with a similar structure and I'm have the same problem.

my structure:
image

server.ts:

'use server'

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

function setEmptyWallet(): ComethWallet {
    try {
        const walletAdaptor = new ConnectAdaptor({
            chainId: SupportedNetworks.MUMBAI,
            apiKey: `${process.env.COMETH_API_KEY
                }`,
        })

        const wallet = new ComethWallet({
            authAdapter: walletAdaptor,
            apiKey: `${process.env.COMETH_API_KEY
                }`,
            rpcUrl:  `https://polygon-mumbai.infura.io/v3/${process.env.INFURA_FPC_ID}`,
        })
        return wallet
    } catch (error) {
        //TODO: error handling
    }
}

export async function setWallet(address: string): Promise<ComethWallet | null> {
    try {
        const wallet = setEmptyWallet()
        await wallet.connect(address)

        return wallet
    } catch (error) {
        throw new Error(`Error getting cometh wallet: ${error}`)
    }
}

export async function createAndSetWallet() {
    try {
        const wallet = setEmptyWallet()

        // Create a new wallet or instance it from an address
        await wallet.connect()

        return wallet
    } catch (error) {
        throw new Error(`Error getting cometh wallet: ${error}`)
    }
}

page.tsx:

"use client";

import Image from "next/image";
import { useEffect } from "react";
import { createAndSetWallet } from "./cometh/server";

export default function Home() {
  useEffect(() => {
    async function connect() {
      const wallet = await createAndSetWallet();
      console.log(wallet);
    }
    connect();
  }, []);

my error:

npm run dev

> [email protected] dev
> next dev

   ▲ Next.js 14.0.3
   - Local:        http://localhost:3000
   - Environments: .env

 ✓ Ready in 3.9s
 ○ Compiling / ...
 ⨯ ./node_modules/@cometh/connect-sdk/dist/wallet/connectors/ConnectOnboardConnector.js:36:98
Module not found: ESM packages (@web3-onboard/common) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@cometh/connect-sdk/dist/wallet/connectors/index.js
./node_modules/@cometh/connect-sdk/dist/wallet/index.js
./node_modules/@cometh/connect-sdk/dist/index.js
./src/app/cometh/server.ts
./node_modules/next/dist/build/webpack/loaders/next-flight-action-entry-loader.js?actions=%5B%5B%22C%3A%5C%5CGitRepo%5C%5CFront-end%5C%5Csrc%5C%5Capp%5C%5Cmongodb%5C%5Cserver.ts%22%2C%5B%22getAccount%22%5D%5D%2C%5B%22C%3A%5C%5CGitRepo%5C%5CFront-end%5C%5Csrc%5C%5Capp%5C%5Ccometh%5C%5Cserver.ts%22%2C%5B%22createAndSetWallet%22%2C%22setWallet%22%5D%5D%5D&__client_imported__=true!
 ⨯ ./node_modules/@cometh/connect-sdk/dist/wallet/connectors/ConnectOnboardConnector.js:36:98

How to reproduce:
npx create-next-app@latest
npm i @cometh/connect-sdk
add some logic in server side
npm run dev

I don't have this problem when I'm on the client side. For example, if I put these functions in a component, then everything works. But it's not secure, so I want everything to happen on the server side.

If you can help me please

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.