Get the state of a wallet
After connecting a Cardano wallet, there are few more functions/attributes to interact with the wallet.
fullName
The fullName attribute represents the wallet's name. If the wallet has a mobile version, a prefix will be added to the wallet name. For instance, eternl
would become mobile-eternl
.
import { anvil } from "@ada-anvil/sdk-client";
try {
await anvil.wallet.connect("eternl");
anvil.wallet.fullName; // Output: "mobile-eternl"
} catch {
console.log("YOUR ERROR HANDLING");
}
name
The name attribute corresponds to the wallet's name, regardless of whether the connection is established on a mobile device or not.
import { anvil } from "@ada-anvil/sdk-client";
try {
await anvil.wallet.connect("eternl");
anvil.wallet.name; // Output: "eternl"
} catch {
console.log("YOUR ERROR HANDLING");
}
info
The info
attribute refers to the pertinent details provided by the wallet, such as the name
, apiVersion
, or the icon
."
import { anvil } from "@ada-anvil/sdk-client";
try {
await anvil.wallet.connect("nami");
anvil.wallet.info; // Output: { apiVersion: "0.1.0", icon: "data:image...", name: "Nami" }
} catch {
console.log("YOUR ERROR HANDLING");
}
isMainnet()
A function that can be used to identify whether the wallet is operating on the mainnet or not.
import { anvil } from "@ada-anvil/sdk-client";
try {
await anvil.wallet.connect("nami");
await anvil.wallet.isMainnet(); // Output: true
} catch {
console.log("YOUR ERROR HANDLING");
}
isConnected()
This function is designed to assess whether the wallet is currently connected or not. See connecting a Cardano wallet section for further context.
import { anvil } from "@ada-anvil/sdk-client";
try {
await anvil.wallet.connect("nami");
await anvil.wallet.isConnected(); // Output: true
} catch {
console.log("YOUR ERROR HANDLING");
}
isConnectedTo()
A function that verifies the connection status of a particular wallet. See connecting a Cardano wallet section for further context.
import { anvil } from "@ada-anvil/sdk-client";
try {
await anvil.wallet.connect("nami");
await anvil.wallet.isConnectedTo("nami"); // Output: true
await anvil.wallet.isConnectedTo("eternl"); // Output: false
} catch {
console.log("YOUR ERROR HANDLING");
}
getNetworkId()
The function provides the network identifier for the presently linked account. Testnet is represented by 0, while mainnet is denoted by 1.
import { anvil } from "@ada-anvil/sdk-client";
try {
await anvil.wallet.connect("nami");
await anvil.wallet.getNetworkId(); // Output: 1
} catch {
console.log("YOUR ERROR HANDLING");
}
getNetworkType()
Same as getNetworkId(), but it is conveyed in a literal representation.
import { anvil } from "@ada-anvil/sdk-client";
try {
await anvil.wallet.connect("nami");
await anvil.wallet.getNetworkType(); // Output: "mainnet"
} catch {
console.log("YOUR ERROR HANDLING");
}