@acala-network/wallet-v2
v0.0.4-20
Published
## Install
Downloads
1,703
Keywords
Readme
Wallet
Install
pnpm install @polkadot/api @acala-network/wallet-v2
Types
Token
const token: Token = {
id: "0x0000",
symbol: "ACA",
decimals: 12,
isNative: true,
isEvm: false,
evm: "0x0000000000000000000100000000000000000000",
};
id
: Token ID used in substrate, can be used to query storage in substratesymbol
: Token symboldecimals
: Token decimalsisNative
: Whether the token is native tokenisEvm
: Whether the token is created by EVMevm
: The EVM address of the token
Account
const account: Account = {
address: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
evm: "0x0000000000000000000100000000000000000000",
isBound: true,
isDefaultEvm: true,
isDefaultSubstrate: false,
};
address
: Substrate addressevm
: EVM addressisBound
: Whether the account has bound EVM address to substrate addressisDefaultEvm
: Whether the account's EVM address is computed from substrate addressisDefaultSubstrate
: Whether the account's substrate address is computed from EVM address
Balance
Balance is based on substrate balance data structure.
For EVM token, setlocked
andreserved
to 0, andavailable
equals tofree
.
const balance: Balance = {
free: 1000000000000000000000000n,
locked: 0n,
reserved: 0n,
available: 1000000000000000000000000n,
};
free
: Free balancelocked
: Locked balancereserved
: Reserved balanceavailable
: Available balance
Usage
- Create a wallet instance
import { Wallet } from "@acala-network/wallet-v2";
import { ApiPromise, WsProvider } from "@polkadot/api";
const api = await ApiPromise.create({
provider: new WsProvider("wss://acala-rpc.polkadot.io"),
});
await api.isReady;
const wallet = new Wallet({
api,
// optional accept a public client, if not passed, the wallet will also create one
publicClient: createPublicClient({
chain: acala,
transport: http(),
}),
});
- Get account
const account = await wallet.getAccount(
// accepts EVM address too
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
);
console.log(account.address);
console.log(account.evm);
- Get registered tokens
const tokens = await wallet.getRegisteredTokenList();
console.log(JSON.stringify(tokens, null, 2));
- Get token by ID or symbol
// accepts token ID, EVM address, or symbol
const token = await wallet.getToken("AUSD");
console.log(token.id);
console.log(token.symbol);
console.log(token.decimals);
- Get balance
const balance = await wallet.getBalance(
// accepts token ID, EVM address, or symbol
"ACA",
// accepts substrate address or EVM address
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
);
console.log(balance);
- Watch balance
const unsubscribe = await wallet.watchBalance(
// accepts token ID, EVM address, or symbol
"ACA",
// accepts substrate address or EVM address
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
(balance) => {
console.log(balance);
unsubscribe();
},
);