ryt-sdk 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +82 -19
- package/dist/config.js +83 -17
- package/dist/contract.d.ts +18 -7
- package/dist/contract.js +37 -29
- package/dist/index.d.ts +58 -19
- package/dist/index.js +62 -19
- package/dist/provider.d.ts +56 -23
- package/dist/provider.js +76 -25
- package/dist/utils/ryt.d.ts +69 -0
- package/dist/utils/ryt.js +64 -0
- package/dist/utils/units.d.ts +20 -0
- package/dist/utils/units.js +25 -0
- package/dist/wallet.d.ts +60 -29
- package/dist/wallet.js +90 -42
- package/package.json +2 -9
package/dist/provider.d.ts
CHANGED
|
@@ -1,49 +1,82 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import type { SDKConfig } from "./config";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Unified blockchain provider instance used across RYT SDK.
|
|
5
|
+
*
|
|
6
|
+
* Provides a single interface for interacting with:
|
|
7
|
+
* - Browser wallet providers (if available)
|
|
8
|
+
* - RPC-based blockchain nodes (fallback)
|
|
9
|
+
*
|
|
10
|
+
* Automatically selects the most appropriate transport layer
|
|
11
|
+
* based on runtime environment and configuration.
|
|
5
12
|
*/
|
|
6
13
|
export default class RYTProvider {
|
|
7
14
|
private provider;
|
|
8
15
|
/**
|
|
9
|
-
*
|
|
16
|
+
* Creates a new provider instance.
|
|
10
17
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
18
|
+
* Selection priority:
|
|
19
|
+
* 1. Injected wallet provider (if enabled and available)
|
|
20
|
+
* 2. RPC provider from config or override
|
|
13
21
|
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
22
|
+
* @param config - SDK configuration containing chain and provider settings
|
|
23
|
+
* @param rpcUrl - Optional override RPC endpoint (takes priority over config)
|
|
24
|
+
*
|
|
25
|
+
* @throws Error if no valid provider source is available
|
|
18
26
|
*/
|
|
19
27
|
constructor(config: SDKConfig, rpcUrl?: string);
|
|
20
28
|
/**
|
|
21
|
-
* Returns the provider instance
|
|
29
|
+
* Returns the underlying provider instance.
|
|
30
|
+
*
|
|
31
|
+
* This may be either:
|
|
32
|
+
* - Browser-based provider (wallet-connected)
|
|
33
|
+
* - RPC-based provider (node connection)
|
|
22
34
|
*
|
|
23
35
|
* @returns provider instance
|
|
24
36
|
*/
|
|
25
|
-
getProvider(): ethers.JsonRpcProvider;
|
|
37
|
+
getProvider(): ethers.BrowserProvider | ethers.JsonRpcProvider;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a signer for transaction signing.
|
|
40
|
+
*
|
|
41
|
+
* Available only when using a browser wallet provider.
|
|
42
|
+
*
|
|
43
|
+
* @throws Error if provider is not a browser wallet instance
|
|
44
|
+
* @returns Signer instance for transaction signing
|
|
45
|
+
*/
|
|
46
|
+
getSigner(): Promise<ethers.Signer>;
|
|
26
47
|
/**
|
|
27
|
-
*
|
|
48
|
+
* Retrieves the connected wallet address.
|
|
28
49
|
*
|
|
29
|
-
*
|
|
50
|
+
* Requires an active browser wallet connection.
|
|
30
51
|
*
|
|
31
|
-
* @
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
52
|
+
* @returns Wallet address string
|
|
53
|
+
*/
|
|
54
|
+
getAddress(): Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves the current network information.
|
|
57
|
+
*
|
|
58
|
+
* @returns Network metadata including chainId and name
|
|
59
|
+
*/
|
|
60
|
+
getNetwork(): Promise<ethers.Network>;
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves the latest block number from the blockchain.
|
|
63
|
+
*
|
|
64
|
+
* @returns Latest block number
|
|
35
65
|
*/
|
|
36
66
|
getBlockNumber(): Promise<number>;
|
|
37
67
|
/**
|
|
38
|
-
*
|
|
68
|
+
* Retrieves the balance of an address.
|
|
39
69
|
*
|
|
40
|
-
* @param address - Ethereum-
|
|
41
|
-
* @returns
|
|
70
|
+
* @param address - Valid Ethereum-compatible address
|
|
71
|
+
* @returns Balance in wei
|
|
42
72
|
*
|
|
43
|
-
* @
|
|
44
|
-
* ```ts
|
|
45
|
-
* const balance = await provider.getBalance("0x123...");
|
|
46
|
-
* ```
|
|
73
|
+
* @throws Error if address is invalid
|
|
47
74
|
*/
|
|
48
75
|
getBalance(address: string): Promise<bigint>;
|
|
76
|
+
/**
|
|
77
|
+
* Checks whether the provider is using a browser wallet.
|
|
78
|
+
*
|
|
79
|
+
* @returns true if injected wallet is active, false if RPC is used
|
|
80
|
+
*/
|
|
81
|
+
isInjected(): boolean;
|
|
49
82
|
}
|
package/dist/provider.js
CHANGED
|
@@ -1,28 +1,46 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
+
import { getRYT } from "./utils/ryt";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
+
* Unified blockchain provider instance used across RYT SDK.
|
|
5
|
+
*
|
|
6
|
+
* Provides a single interface for interacting with:
|
|
7
|
+
* - Browser wallet providers (if available)
|
|
8
|
+
* - RPC-based blockchain nodes (fallback)
|
|
9
|
+
*
|
|
10
|
+
* Automatically selects the most appropriate transport layer
|
|
11
|
+
* based on runtime environment and configuration.
|
|
4
12
|
*/
|
|
5
13
|
export default class RYTProvider {
|
|
6
14
|
/**
|
|
7
|
-
*
|
|
15
|
+
* Creates a new provider instance.
|
|
8
16
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
17
|
+
* Selection priority:
|
|
18
|
+
* 1. Injected wallet provider (if enabled and available)
|
|
19
|
+
* 2. RPC provider from config or override
|
|
11
20
|
*
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
21
|
+
* @param config - SDK configuration containing chain and provider settings
|
|
22
|
+
* @param rpcUrl - Optional override RPC endpoint (takes priority over config)
|
|
23
|
+
*
|
|
24
|
+
* @throws Error if no valid provider source is available
|
|
16
25
|
*/
|
|
17
26
|
constructor(config, rpcUrl) {
|
|
18
|
-
const rpc = rpcUrl ?? config.rpcUrls[0];
|
|
27
|
+
const rpc = rpcUrl ?? config.rpcUrls?.[0];
|
|
28
|
+
const injected = getRYT();
|
|
29
|
+
if (injected && config.enableBrowserWallet !== false) {
|
|
30
|
+
this.provider = new ethers.BrowserProvider(injected);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
19
33
|
if (!rpc) {
|
|
20
|
-
throw new Error("No
|
|
34
|
+
throw new Error("No provider available (no RPC or wallet)");
|
|
21
35
|
}
|
|
22
36
|
this.provider = new ethers.JsonRpcProvider(rpc);
|
|
23
37
|
}
|
|
24
38
|
/**
|
|
25
|
-
* Returns the provider instance
|
|
39
|
+
* Returns the underlying provider instance.
|
|
40
|
+
*
|
|
41
|
+
* This may be either:
|
|
42
|
+
* - Browser-based provider (wallet-connected)
|
|
43
|
+
* - RPC-based provider (node connection)
|
|
26
44
|
*
|
|
27
45
|
* @returns provider instance
|
|
28
46
|
*/
|
|
@@ -30,33 +48,66 @@ export default class RYTProvider {
|
|
|
30
48
|
return this.provider;
|
|
31
49
|
}
|
|
32
50
|
/**
|
|
33
|
-
*
|
|
51
|
+
* Returns a signer for transaction signing.
|
|
34
52
|
*
|
|
35
|
-
*
|
|
53
|
+
* Available only when using a browser wallet provider.
|
|
36
54
|
*
|
|
37
|
-
* @
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
55
|
+
* @throws Error if provider is not a browser wallet instance
|
|
56
|
+
* @returns Signer instance for transaction signing
|
|
57
|
+
*/
|
|
58
|
+
async getSigner() {
|
|
59
|
+
if (!(this.provider instanceof ethers.BrowserProvider)) {
|
|
60
|
+
throw new Error("Signer not available in RPC mode");
|
|
61
|
+
}
|
|
62
|
+
return await this.provider.getSigner();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Retrieves the connected wallet address.
|
|
66
|
+
*
|
|
67
|
+
* Requires an active browser wallet connection.
|
|
68
|
+
*
|
|
69
|
+
* @returns Wallet address string
|
|
70
|
+
*/
|
|
71
|
+
async getAddress() {
|
|
72
|
+
const signer = await this.getSigner();
|
|
73
|
+
return await signer.getAddress();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves the current network information.
|
|
77
|
+
*
|
|
78
|
+
* @returns Network metadata including chainId and name
|
|
79
|
+
*/
|
|
80
|
+
async getNetwork() {
|
|
81
|
+
return await this.provider.getNetwork();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves the latest block number from the blockchain.
|
|
85
|
+
*
|
|
86
|
+
* @returns Latest block number
|
|
41
87
|
*/
|
|
42
88
|
async getBlockNumber() {
|
|
43
89
|
return await this.provider.getBlockNumber();
|
|
44
90
|
}
|
|
45
91
|
/**
|
|
46
|
-
*
|
|
92
|
+
* Retrieves the balance of an address.
|
|
47
93
|
*
|
|
48
|
-
* @param address - Ethereum-
|
|
49
|
-
* @returns
|
|
94
|
+
* @param address - Valid Ethereum-compatible address
|
|
95
|
+
* @returns Balance in wei
|
|
50
96
|
*
|
|
51
|
-
* @
|
|
52
|
-
* ```ts
|
|
53
|
-
* const balance = await provider.getBalance("0x123...");
|
|
54
|
-
* ```
|
|
97
|
+
* @throws Error if address is invalid
|
|
55
98
|
*/
|
|
56
99
|
async getBalance(address) {
|
|
57
100
|
if (!ethers.isAddress(address)) {
|
|
58
|
-
throw new Error(
|
|
101
|
+
throw new Error("Invalid address");
|
|
59
102
|
}
|
|
60
103
|
return await this.provider.getBalance(address);
|
|
61
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Checks whether the provider is using a browser wallet.
|
|
107
|
+
*
|
|
108
|
+
* @returns true if injected wallet is active, false if RPC is used
|
|
109
|
+
*/
|
|
110
|
+
isInjected() {
|
|
111
|
+
return this.provider instanceof ethers.BrowserProvider;
|
|
112
|
+
}
|
|
62
113
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal EIP-1193 provider interface.
|
|
3
|
+
*
|
|
4
|
+
* Represents a browser-injected wallet provider such as:
|
|
5
|
+
* - MetaMask
|
|
6
|
+
* - Rabby
|
|
7
|
+
* - Coinbase Wallet
|
|
8
|
+
*
|
|
9
|
+
* This interface standardizes communication with injected wallets
|
|
10
|
+
* using the EIP-1193 request/response pattern.
|
|
11
|
+
*/
|
|
12
|
+
export interface RYTProvider {
|
|
13
|
+
request: (args: {
|
|
14
|
+
method: string;
|
|
15
|
+
params?: any[];
|
|
16
|
+
}) => Promise<any>;
|
|
17
|
+
on?: (event: string, handler: (...args: any[]) => void) => void;
|
|
18
|
+
removeListener?: (event: string, handler: (...args: any[]) => void) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Safely retrieves the injected provider from the browser.
|
|
22
|
+
*
|
|
23
|
+
* This function:
|
|
24
|
+
* - Works in browser environments only
|
|
25
|
+
* - Is SSR-safe (Next.js / Vite / Node.js compatible)
|
|
26
|
+
* - Returns undefined if no wallet is installed
|
|
27
|
+
*
|
|
28
|
+
* @returns provider instance if available, otherwise undefined
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const ryt = getRYT();
|
|
32
|
+
* if (ryt) {
|
|
33
|
+
* console.log("Wallet is available");
|
|
34
|
+
* }
|
|
35
|
+
*/
|
|
36
|
+
export declare function getRYT(): RYTProvider | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Checks whether an injected wallet is available.
|
|
39
|
+
*
|
|
40
|
+
* This is a convenience helper around `getRYT()`.
|
|
41
|
+
* Useful for conditionally enabling wallet-based features.
|
|
42
|
+
*
|
|
43
|
+
* @returns true if a wallet (MetaMask / similar) is detected, otherwise false
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* if (!hasRYT()) {
|
|
47
|
+
* alert("Please install MetaMask");
|
|
48
|
+
* }
|
|
49
|
+
*/
|
|
50
|
+
export declare function hasRYT(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Requests account access from the user's wallet.
|
|
53
|
+
*
|
|
54
|
+
* This triggers the wallet popup (e.g. MetaMask approval dialog)
|
|
55
|
+
* using the EIP-1193 `eth_requestAccounts` method.
|
|
56
|
+
*
|
|
57
|
+
* Requirements:
|
|
58
|
+
* - Must be called in a browser environment
|
|
59
|
+
* - Requires an injected wallet (MetaMask, etc.)
|
|
60
|
+
*
|
|
61
|
+
* @returns Promise resolving to an array of connected wallet addresses
|
|
62
|
+
*
|
|
63
|
+
* @throws Error if no injected wallet is available
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const accounts = await requestAccounts();
|
|
67
|
+
* console.log(accounts[0]);
|
|
68
|
+
*/
|
|
69
|
+
export declare function requestAccounts(): Promise<string[]>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely retrieves the injected provider from the browser.
|
|
3
|
+
*
|
|
4
|
+
* This function:
|
|
5
|
+
* - Works in browser environments only
|
|
6
|
+
* - Is SSR-safe (Next.js / Vite / Node.js compatible)
|
|
7
|
+
* - Returns undefined if no wallet is installed
|
|
8
|
+
*
|
|
9
|
+
* @returns provider instance if available, otherwise undefined
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const ryt = getRYT();
|
|
13
|
+
* if (ryt) {
|
|
14
|
+
* console.log("Wallet is available");
|
|
15
|
+
* }
|
|
16
|
+
*/
|
|
17
|
+
export function getRYT() {
|
|
18
|
+
if (typeof globalThis === "undefined")
|
|
19
|
+
return undefined;
|
|
20
|
+
const eth = globalThis.ethereum;
|
|
21
|
+
if (!eth)
|
|
22
|
+
return undefined;
|
|
23
|
+
return eth;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks whether an injected wallet is available.
|
|
27
|
+
*
|
|
28
|
+
* This is a convenience helper around `getRYT()`.
|
|
29
|
+
* Useful for conditionally enabling wallet-based features.
|
|
30
|
+
*
|
|
31
|
+
* @returns true if a wallet (MetaMask / similar) is detected, otherwise false
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* if (!hasRYT()) {
|
|
35
|
+
* alert("Please install MetaMask");
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
export function hasRYT() {
|
|
39
|
+
return !!getRYT();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Requests account access from the user's wallet.
|
|
43
|
+
*
|
|
44
|
+
* This triggers the wallet popup (e.g. MetaMask approval dialog)
|
|
45
|
+
* using the EIP-1193 `eth_requestAccounts` method.
|
|
46
|
+
*
|
|
47
|
+
* Requirements:
|
|
48
|
+
* - Must be called in a browser environment
|
|
49
|
+
* - Requires an injected wallet (MetaMask, etc.)
|
|
50
|
+
*
|
|
51
|
+
* @returns Promise resolving to an array of connected wallet addresses
|
|
52
|
+
*
|
|
53
|
+
* @throws Error if no injected wallet is available
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const accounts = await requestAccounts();
|
|
57
|
+
* console.log(accounts[0]);
|
|
58
|
+
*/
|
|
59
|
+
export async function requestAccounts() {
|
|
60
|
+
const eth = getRYT();
|
|
61
|
+
if (!eth)
|
|
62
|
+
throw new Error("No injected wallet found");
|
|
63
|
+
return eth.request({ method: "eth_requestAccounts" });
|
|
64
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts human-readable token amount into smallest unit (wei-like format).
|
|
3
|
+
*
|
|
4
|
+
*
|
|
5
|
+
* @param amount - human readable value (e.g. "1.5")
|
|
6
|
+
* @param decimals - token decimals (e.g. 18)
|
|
7
|
+
* @returns bigint in smallest unit
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* parseTokenUnits("1.5", 18)
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseTokenUnits(amount: string, decimals: number): bigint;
|
|
13
|
+
/**
|
|
14
|
+
* Converts smallest unit back to human-readable value.
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* @param value - bigint or string
|
|
18
|
+
* @param decimals - token decimals
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatTokenUnits(value: bigint | string, decimals: number): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
/**
|
|
3
|
+
* Converts human-readable token amount into smallest unit (wei-like format).
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* @param amount - human readable value (e.g. "1.5")
|
|
7
|
+
* @param decimals - token decimals (e.g. 18)
|
|
8
|
+
* @returns bigint in smallest unit
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* parseTokenUnits("1.5", 18)
|
|
12
|
+
*/
|
|
13
|
+
export function parseTokenUnits(amount, decimals) {
|
|
14
|
+
return ethers.parseUnits(amount, decimals);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts smallest unit back to human-readable value.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* @param value - bigint or string
|
|
21
|
+
* @param decimals - token decimals
|
|
22
|
+
*/
|
|
23
|
+
export function formatTokenUnits(value, decimals) {
|
|
24
|
+
return ethers.formatUnits(value, decimals);
|
|
25
|
+
}
|
package/dist/wallet.d.ts
CHANGED
|
@@ -1,63 +1,94 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import type RYTProvider from "./provider";
|
|
3
3
|
/**
|
|
4
|
-
* Transaction request
|
|
4
|
+
* Transaction request structure for blockchain operations.
|
|
5
5
|
*/
|
|
6
6
|
export type TxRequest = ethers.TransactionRequest;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Unified wallet abstraction for RYT SDK.
|
|
9
|
+
*
|
|
10
|
+
* Supports:
|
|
11
|
+
* - Private key wallets (Node.js / backend)
|
|
12
|
+
* - Browser injected wallets (MetaMask, Rabby, etc.)
|
|
13
|
+
*
|
|
14
|
+
* Automatically adapts behavior based on runtime environment.
|
|
9
15
|
*/
|
|
10
16
|
export default class RYTWallet {
|
|
11
|
-
private
|
|
17
|
+
private signer;
|
|
12
18
|
/**
|
|
13
|
-
* Create a new
|
|
19
|
+
* Create a new wallet instance.
|
|
14
20
|
*
|
|
15
|
-
*
|
|
16
|
-
* @param provider - Optional RYTProvider instance for network access
|
|
21
|
+
* The wallet can operate in two modes:
|
|
17
22
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
23
|
+
* 1. Backend mode (private key provided)
|
|
24
|
+
* - Full signing capability
|
|
25
|
+
* - Used in Node.js scripts, servers, bots
|
|
26
|
+
*
|
|
27
|
+
* 2. Browser mode (injected wallet)
|
|
28
|
+
* - Uses connected wallet (MetaMask, etc.)
|
|
29
|
+
* - No private key required or allowed
|
|
30
|
+
*
|
|
31
|
+
* @param signerOrPrivateKey
|
|
32
|
+
* - string → private key (backend mode)
|
|
33
|
+
* - signer → injected browser signer
|
|
34
|
+
*
|
|
35
|
+
* @param provider Optional provider instance for network access
|
|
36
|
+
*
|
|
37
|
+
* @throws Error if invalid input is provided
|
|
38
|
+
*
|
|
39
|
+
* @example Backend:
|
|
20
40
|
* const wallet = new RYTWallet(PRIVATE_KEY, provider);
|
|
21
|
-
*
|
|
41
|
+
*
|
|
42
|
+
* @example Browser:
|
|
43
|
+
* const wallet = new RYTWallet(signer);
|
|
22
44
|
*/
|
|
23
|
-
constructor(
|
|
45
|
+
constructor(signerOrPrivateKey: string | ethers.Signer, provider?: RYTProvider);
|
|
24
46
|
/**
|
|
25
|
-
*
|
|
47
|
+
* Get wallet address.
|
|
26
48
|
*
|
|
27
49
|
* @returns Wallet public address
|
|
28
50
|
*
|
|
29
51
|
* @example
|
|
30
|
-
*
|
|
31
|
-
* const address = wallet.getAddress();
|
|
32
|
-
* ```
|
|
52
|
+
* const address = await wallet.getAddress();
|
|
33
53
|
*/
|
|
34
|
-
getAddress(): string
|
|
54
|
+
getAddress(): Promise<string>;
|
|
35
55
|
/**
|
|
36
|
-
* Get wallet balance in wei
|
|
56
|
+
* Get wallet balance in wei.
|
|
37
57
|
*
|
|
38
|
-
*
|
|
58
|
+
* Requires connected provider (RPC or injected).
|
|
39
59
|
*
|
|
40
|
-
* @
|
|
60
|
+
* @returns Balance in wei
|
|
41
61
|
*
|
|
42
|
-
* @
|
|
43
|
-
* ```ts
|
|
44
|
-
* const balance = await wallet.getBalance();
|
|
45
|
-
* ```
|
|
62
|
+
* @throws Error if provider is not available
|
|
46
63
|
*/
|
|
47
64
|
getBalance(): Promise<bigint>;
|
|
48
65
|
/**
|
|
49
|
-
* Send a
|
|
66
|
+
* Send a blockchain transaction.
|
|
50
67
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
68
|
+
* Works in both:
|
|
69
|
+
* - Backend (signed via private key)
|
|
70
|
+
* - Browser (signed via MetaMask / injected wallet)
|
|
71
|
+
*
|
|
72
|
+
* @param tx Transaction request object
|
|
73
|
+
* @returns Transaction response
|
|
53
74
|
*
|
|
54
75
|
* @example
|
|
55
|
-
* ```ts
|
|
56
76
|
* await wallet.sendTransaction({
|
|
57
|
-
* to: "
|
|
58
|
-
* value:
|
|
77
|
+
* to: "0x...",
|
|
78
|
+
* value: "0.01"
|
|
59
79
|
* });
|
|
60
|
-
* ```
|
|
61
80
|
*/
|
|
62
81
|
sendTransaction(tx: TxRequest): Promise<ethers.TransactionResponse>;
|
|
82
|
+
/**
|
|
83
|
+
* Check if wallet is connected to a provider.
|
|
84
|
+
*
|
|
85
|
+
* @returns true if provider is available
|
|
86
|
+
*/
|
|
87
|
+
isConnected(): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Get underlying signer instance.
|
|
90
|
+
*
|
|
91
|
+
* Useful for advanced contract interactions.
|
|
92
|
+
*/
|
|
93
|
+
getSigner(): ethers.Signer;
|
|
63
94
|
}
|