Ethers
Ethers version of the connect sdk
Installβ
npm i @cometh/connect-sdk
Init Wallet
import {
ComethWallet,
ConnectAdaptor,
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
})
Wallet methods
await wallet.connect()
// connect to existing wallet
await wallet.connect(walletAddress)
wallet.getAddress()
import {
ComethWallet,
ConnectAdaptor,
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 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();
const provider = new ComethProvider(wallet)
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();
const signature = await wallet.signMessage('hello')
Interact with ethers contract interface
import {
ComethWallet,
ConnectAdaptor,
ComethProvider,
SupportedNetworks
} from '@cometh/connect-sdk'
const walletAdaptor = new ConnectAdaptor({
chainId: YOUR_CHAIN_ID,
apiKey: API_KEY,
passKeyName
})
const wallet = new ComethWallet({
authAdapter: walletAdaptor,
apiKey: API_KEY,
rpcUrl: RPC_URL
})
const provider = new ComethProvider(wallet)
const counterContract = new ethers.Contract(
CONTRACT_ADDRESS,
counterContractAbi,
provider.getSigner()
)
const tx = await counterContract.count()
const txReceipt = await tx.wait()
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: YOUR_CHAIN_ID,
apiKey: API_KEY,
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'
}
]
})
Last updated