@perawallet/use-wallet-pera
v1.0.0
Published
Pera Wallet adapter for @txnlab/use-wallet, maintained by Pera Wallet
Readme
@perawallet/use-wallet-pera
The Pera Wallet adapter for use-wallet, maintained by Pera.
It wraps @perawallet/connect, so one adapter covers the Pera mobile app (WalletConnect), Pera Web and the Pera browser extension.
Installation
pnpm add @txnlab/use-wallet @perawallet/use-wallet-pera algosdkIf you use a framework adapter (@txnlab/use-wallet-react, -vue, -solid or -svelte), install it instead of @txnlab/use-wallet.
Requires @txnlab/use-wallet 5.x and algosdk 3.5.2 or later.
Usage
import { WalletManager } from "@txnlab/use-wallet";
import { pera } from "@perawallet/use-wallet-pera";
const manager = new WalletManager({
wallets: [pera()],
});pera() accepts every PeraWalletConnect option and passes them through unchanged, plus use-wallet's shared metadata option to change the name or icon shown for the wallet:
pera({
shouldShowSignTxnToast: false,
compactMode: true,
metadata: { name: "Pera Wallet" },
});The adapter supports MainNet and TestNet, transaction signing (signTransactions and transactionSigner) and ARC-60 data signing (signData).
Migrating from @txnlab/use-wallet-pera
Swap the package and the import. Nothing else changes:
- import { pera } from "@txnlab/use-wallet-pera";
+ import { pera } from "@perawallet/use-wallet-pera";The wallet id is still "pera", so sessions that use-wallet has already persisted are picked up as they are and users stay connected across the upgrade.
What's different from the TxnLab package:
- Pera browser extension sessions. Revoking a site from the extension's Connections screen now disconnects the wallet in your app. The old adapter only listened on the WalletConnect connector, which extension sessions don't have.
- All connect options. Options such as
singleAccount,shouldPreferExtensionandalgodare passed through, not justbridge,shouldShowSignTxnToast,chainIdandcompactMode. - Typed signing errors. A rejected or failed signing request throws use-wallet's
SignTxnsErrororSignDataError. The code is4001when the user cancelled and4300otherwise, and the original Pera error type is inerror.data.type. - A strict response count. If the wallet returns a different number of signed transactions than it was asked for,
signTransactionsthrows instead of returning a misaligned array. - Sharing an app with other WalletConnect wallets. From connect 1.7, Pera keeps its WalletConnect session under its own storage key, so it no longer competes with other WalletConnect v1 wallets for the shared one. Pera's session also resumes on page load while another wallet is active.
Error handling
import { SignTxnsError } from "@txnlab/use-wallet";
try {
await wallet.signTransactions(txns);
} catch (error) {
if (error instanceof SignTxnsError && error.code === 4001) {
// the user rejected the request in Pera
}
}Contributing
See CONTRIBUTING.md. Report security issues through GitHub private vulnerability reporting on this repository, not in a public issue.
License
MIT. This package began as a fork of TxnLab's @txnlab/use-wallet-pera.
