@azguardwallet/aztec-wallet
v3.0.0-devnet.20251212
Published
Azguard Wallet client fully compatible with Aztec.js' Wallet interface
Downloads
37
Readme
@azguardwallet/aztec-wallet
Azguard Wallet client fully compatible with Aztec.js' Wallet interface, enabling seamless integration.
How to use
Install the package:
npm install @azguardwallet/aztec-walletConnect the wallet:
import { AztecWallet } from "@azguardwallet/aztec-wallet";
// the simplest way
const wallet = await AztecWallet.connect();
// or you can additionally provide the dapp metadata and the chain
const wallet = await AztecWallet.connect(
{
name: "My Dapp",
description: "The best dapp in the world",
logo: "...",
url: "..."
},
"devnet" // or "sandbox", or CAIP-string like "aztec:1654394782"
);Then use this wallet for interaction with Aztec.js:
import { AztecAddress } from '@aztec/aztec.js/addresses';
import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee';
import { createAztecNodeClient } from '@aztec/aztec.js/node';
import { TokenContract, TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
const accounts = await wallet.getAccounts();
const address = accounts[0].item;
const tokenAddress = AztecAddress.fromString("0x...");
const tokenContract = await TokenContract.at(tokenAddress, wallet);
// register token contract in user's PXE
const node = createAztecNodeClient("https://next.devnet.aztec-labs.com");
const tokenInstance = await node.getContract(tokenAddress);
await wallet.registerContract(tokenInstance, TokenContractArtifact);
// get token private balance
const prvBalance = await tokenContract.methods
.balance_of_private(address)
.simulate({from: address});
console.log("Private balance", prvBalance);
// get token public balance
const pubBalance = await tokenContract.methods
.balance_of_public(address)
.simulate({from: address});
console.log("Public balance", pubBalance);
// send token
const feeOptions = {
paymentMethod: new SponsoredFeePaymentMethod(
AztecAddress.fromString("0x..."),
),
};
const txReceipt = await tokenContract.methods
.transfer(AztecAddress.fromString("0x..."), 100000000n)
.send({from: address, fee: feeOptions})
.wait();
console.log("Tx hash", txReceipt.txHash);That's pretty much it! See more Aztec.js examples at https://docs.aztec.network.
Connection state
When Azguard user confirms connection from a dapp (AztecWallet.connect()), a dapp session is opened, and while this session is active, the dapp is allowed to interact with the wallet. If the dapp session is expired or closed (either by the dapp or by the user), the interaction is no longer allowed.
Even though the AztecWallet client reconnects automatically, you might want to additionally track the connection state. You can do the following:
// connect the wallet
// (it's lazily called under the hood, so you don't have to call it manually,
// unless you want to connect immediately)
await wallet.connect();
// check if the wallet is connected
console.log(wallet.connected);
// track connection/disconnection events
wallet.onConnected.addHandler(() => console.log("Azguard connected"));
wallet.onDisconnected.addHandler(() => console.log("Azguard disconnected"));
// in the end you can disconnect and close the session
await wallet.disconnect();Support channels
If you have any questions, feel free to contact us in:
- Telegram: https://t.me/azguardwallet
- Twitter: https://twitter.com/AzguardWallet
Cheers! 🍺
