Last active
August 3, 2022 09:09
-
-
Save asbjornenge/b67df739d50a2716a6d048a36ed53f27 to your computer and use it in GitHub Desktop.
ChainBorn Wallet Connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TezosToolkit } from '@taquito/taquito' | |
import { BeaconWallet } from '@taquito/beacon-wallet' | |
const Tezos = new TezosToolkit() | |
const wallet = new BeaconWallet({ name: "ChainBorn" }) | |
Tezos.setWalletProvider(wallet) | |
export async function setProvider(rpc) { | |
Tezos.setProvider({ rpc: rpc}) | |
} | |
export async function getActiveAccount() { | |
const activeAccount = await wallet.client.getActiveAccount() | |
if (!activeAccount) return null | |
return activeAccount | |
} | |
export async function connectWallet(network) { | |
const account = await wallet.client.requestPermissions({ | |
network: { | |
type: network.type, | |
rpcUrl: network.rpc | |
} | |
}) | |
return account | |
} | |
export async function disconnectWallet() { | |
await wallet.clearActiveAccount() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment