## Usage
npm install @alphasquare/connect-walletYou must run this function first to setup the smart contract connection. The other methods won't work until you've successfully initialized the package.
``ts`
if (window.alphasquare.initialized) {
return;
} else {
window.alphasquare.init({
chain: {
id: "
token: "
label: "
rpcUrl: "
},
subscriptionAddress: "
alphaAddress: "
appMetadata: {
name: "AlphaSquare",
icon: "
logo: "
description: "
recommendedInjectedWallets: [
{ name: "Coinbase", url: "https://wallet.coinbase.com/" },
{ name: "MetaMask", url: "https://metamask.io" },
],
},
});
}
`ts
const result = await window.alphasquare.connectWallet();
console.log(result);
/**
* {
* "address": "0x1234...",
* "ens"?: {
* "name": "example.eth",
* "avatar": {
* "linkage": [
* {
* "type": "name",
* "content": "example.eth"
* },
* {
* "type": "url",
* "content": "https://example.com/image"
* }
* ],
* "url": "https://example.com/image"
* },
* "contentHash": null
* },
* "icon": " * "label": "MetaMask",
* "success": true
* }
*/
`
`ts
const result = await window.alphasquare.disconnectWallet();
console.log(result); // true
`
`ts
const result = await window.alphasquare.getAlphaBalance();
console.log(result); // 1000
`
`ts
await window.alphasquare.connectWallet();
await window.alphasquare.approveAlpha(10);
const subscriptionTx = await window.alphasquare.subscribe(USER_ID); // USER_ID should be the AlphaSquare user ID not the wallet address
const result = await window.alphasquare.isSubscriptionValid(USER_ID);
console.log(result); // true
`
To be used when you need to confirm if the current users owns the wallet they say they do, e.g. before creating an Alpha NFT.
This function is already built into the connect wallet flow.
`ts
const result = await window.alphasquare.verifyOwnership(
"Some string to display in wallet"
);
console.log(result); // true
`
Set a callback to be called when all wallets have been disconnected.
`ts``
window.alphasquare.setDisconnectCallback(() => {
console.log("All wallets disconnected.");
});