Package Exports
- @perawallet/connect
- @perawallet/connect/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@perawallet/connect) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@perawallet/connect
JavaScript SDK for integrating Pera Wallet to web applications.
Getting Started
Learn how to integrate with your JavaScript application
Example Applications
Guide
Let's start with installing @perawallet/connect
npm install --save @perawallet/connectUsing React Hooks
import {PeraWalletConnect} from "@perawallet/connect";
// Create the PeraWalletConnect instance outside of the component
const peraWallet = new PeraWalletConnect();
function App() {
const [accountAddress, setAccountAddress] = useState<string | null>(null);
const isConnectedToPeraWallet = !!accountAddress;
useEffect(() => {
// Reconnect to the session when the component is mounted
peraWallet.reconnectSession().then((accounts) => {
// Setup the disconnect event listener
peraWallet.connector?.on("disconnect", handleDisconnectWalletClick);
if (accounts.length) {
setAccountAddress(accounts[0]);
}
});
}, []);
return (
<button
onClick={
isConnectedToPeraWallet ? handleDisconnectWalletClick : handleConnectWalletClick
}>
{isConnectedToPeraWallet ? "Disconnect" : "Connect to Pera Wallet"}
</button>
);
function handleConnectWalletClick() {
peraWallet.connect().then((newAccounts) => {
// Setup the disconnect event listener
peraWallet.connector?.on("disconnect", handleDisconnectWalletClick);
setAccountAddress(newAccounts[0]);
});
}
function handleDisconnectWalletClick() {
peraWallet.disconnect();
setAccountAddress(null);
}
}Your app name on Pera Wallet
By default, the connect wallet drawer on Pera Wallet gets the app name from document.title.
In some cases, you may want to customize it. You can achieve this by adding a meta tag to your HTML between the head tag.
<meta name="name" content="My dApp" />