-
Notifications
You must be signed in to change notification settings - Fork 13
WDK Core Documentation Refactor #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
0fd5ab2
994287c
eaa3108
8dcf673
b30ab97
67fa9c0
16e1aa2
7e52e3e
a108eca
b0225fe
3f106fb
e72c120
ce36549
484107c
766cb18
f76f535
9a9e7a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,111 @@ | ||||||||||||||||
| --- | ||||||||||||||||
| title: Manage Accounts | ||||||||||||||||
| description: Learn how to work with accounts and addresses. | ||||||||||||||||
| layout: | ||||||||||||||||
| width: default | ||||||||||||||||
| title: | ||||||||||||||||
| visible: true | ||||||||||||||||
| description: | ||||||||||||||||
| visible: true | ||||||||||||||||
| tableOfContents: | ||||||||||||||||
| visible: true | ||||||||||||||||
| outline: | ||||||||||||||||
| visible: true | ||||||||||||||||
| pagination: | ||||||||||||||||
| visible: false | ||||||||||||||||
| metadata: | ||||||||||||||||
| visible: false | ||||||||||||||||
| --- | ||||||||||||||||
|
|
||||||||||||||||
| # Manage Accounts | ||||||||||||||||
|
|
||||||||||||||||
| This guide explains how to access accounts from your registered wallets. An "Account" object in WDK is your interface for inspecting balances and sending transactions on a specific blockchain. | ||||||||||||||||
|
|
||||||||||||||||
| ## Retrieve Accounts | ||||||||||||||||
|
|
||||||||||||||||
| You can retrieve an account using a simple index or a custom derivation path. | ||||||||||||||||
|
|
||||||||||||||||
| ### By Index (Recommended) | ||||||||||||||||
|
|
||||||||||||||||
| The simplest way to get an account is by its index (starting at `0`). This uses the default derivation path for the specified blockchain. | ||||||||||||||||
|
|
||||||||||||||||
| {% code title="Get Account by Index" lineNumbers="true" %} | ||||||||||||||||
| ```typescript | ||||||||||||||||
| // Get the first account (index 0) for Ethereum and TON | ||||||||||||||||
| const ethAccount = await wdk.getAccount('ethereum', 0) | ||||||||||||||||
| const tonAccount = await wdk.getAccount('ton', 0) | ||||||||||||||||
| ``` | ||||||||||||||||
| {% endcode %} | ||||||||||||||||
|
|
||||||||||||||||
| ### By Derivation Path (Advanced) | ||||||||||||||||
|
|
||||||||||||||||
| If you need a specific hierarchy, you can request an account by its unique derivation path. | ||||||||||||||||
|
|
||||||||||||||||
| {% code title="Get Account by Path" lineNumbers="true" %} | ||||||||||||||||
| ```typescript | ||||||||||||||||
| // Custom path for Ethereum | ||||||||||||||||
| const customEthAccount = await wdk.getAccountByPath('ethereum', "0'/0/1") | ||||||||||||||||
| ``` | ||||||||||||||||
| {% endcode %} | ||||||||||||||||
|
|
||||||||||||||||
| {% hint style="info" %} | ||||||||||||||||
| The WDK instance caches accounts. calling `getAccount` twice for the same index returns the same object instance. | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| {% endhint %} | ||||||||||||||||
|
|
||||||||||||||||
| {% hint style="warning" %} | ||||||||||||||||
| **Network Mismatch Warning** | ||||||||||||||||
| Ensure your WDK instance configuration matches your account environment. | ||||||||||||||||
| * If using **Testnet** keys, ensure you registered the wallet with a **Testnet RPC**. | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add links to the RPCs |
||||||||||||||||
| * If using **Mainnet** keys, ensure you registered the wallet with a **Mainnet RPC**. | ||||||||||||||||
| Using a Mainnet key on a Testnet RPC (or vice versa) will result in "Network not allowed" or 0 balance errors. | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We should spell out numbers unless they are being used in opertions. |
||||||||||||||||
| {% endhint %} | ||||||||||||||||
|
|
||||||||||||||||
| ## View Addresses | ||||||||||||||||
|
|
||||||||||||||||
| Once you have an account object, you can retrieve its public blockchain address. | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| {% code title="Get Addresses" lineNumbers="true" %} | ||||||||||||||||
| ```typescript | ||||||||||||||||
| const ethAddress = await ethAccount.getAddress() | ||||||||||||||||
| console.log('Ethereum address:', ethAddress) | ||||||||||||||||
| ``` | ||||||||||||||||
| {% endcode %} | ||||||||||||||||
|
|
||||||||||||||||
| ## Check Balances | ||||||||||||||||
|
|
||||||||||||||||
| You can check the native token balance of any account (e.g., ETH on Ethereum, TON on TON). | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| {% code title="Get Balance" lineNumbers="true" %} | ||||||||||||||||
| ```typescript | ||||||||||||||||
| try { | ||||||||||||||||
| const balance = await ethAccount.getBalance() | ||||||||||||||||
| console.log('Balance:', balance) | ||||||||||||||||
| } catch (error) { | ||||||||||||||||
| console.error('Failed to fetch balance:', error) | ||||||||||||||||
| } | ||||||||||||||||
| ``` | ||||||||||||||||
| {% endcode %} | ||||||||||||||||
|
|
||||||||||||||||
| ### Multi-Chain Balance Check | ||||||||||||||||
|
|
||||||||||||||||
| Because WDK offers a unified interface, you can easily iterate through multiple chains to fetch balances. | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| {% code title="Check All Balances" lineNumbers="true" %} | ||||||||||||||||
| ```typescript | ||||||||||||||||
| const chains = ['ethereum', 'ton', 'bitcoin'] | ||||||||||||||||
|
|
||||||||||||||||
| for (const chain of chains) { | ||||||||||||||||
| try { | ||||||||||||||||
| const account = await wdk.getAccount(chain, 0) | ||||||||||||||||
| const balance = await account.getBalance() | ||||||||||||||||
| console.log(`${chain} balance:`, balance) | ||||||||||||||||
| } catch (error) { | ||||||||||||||||
| console.log(`${chain}: Wallet not registered or unavailable`) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| ``` | ||||||||||||||||
| {% endcode %} | ||||||||||||||||
|
|
||||||||||||||||
| ## Next steps | ||||||||||||||||
|
|
||||||||||||||||
| Now that you can access your accounts, learn how to [send transactions](./transactions.md). | ||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||||
| --- | ||||||||||||||||||||
| title: Error Handling | ||||||||||||||||||||
| description: Learn about common errors and best practices. | ||||||||||||||||||||
| layout: | ||||||||||||||||||||
| width: default | ||||||||||||||||||||
| title: | ||||||||||||||||||||
| visible: true | ||||||||||||||||||||
| description: | ||||||||||||||||||||
| visible: true | ||||||||||||||||||||
| tableOfContents: | ||||||||||||||||||||
| visible: true | ||||||||||||||||||||
| outline: | ||||||||||||||||||||
| visible: true | ||||||||||||||||||||
| pagination: | ||||||||||||||||||||
| visible: false | ||||||||||||||||||||
| metadata: | ||||||||||||||||||||
| visible: false | ||||||||||||||||||||
| --- | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Error Handling & Best Practices | ||||||||||||||||||||
|
|
||||||||||||||||||||
| This guide covers recommended patterns for error handling and security when using the WDK. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ## Handling Common Errors | ||||||||||||||||||||
|
|
||||||||||||||||||||
| When interacting with multiple chains and protocols, various runtime issues may occur. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ### Missing Registration | ||||||||||||||||||||
|
|
||||||||||||||||||||
| The most common error is attempting to access a wallet or protocol that hasn't been registered. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| {% code title="Check Registration Pattern" lineNumbers="true" %} | ||||||||||||||||||||
| ```typescript | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| // This will throw if 'tron' was never registered via .registerWallet() | ||||||||||||||||||||
| const tronAccount = await wdk.getAccount('tron', 0) | ||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||
| console.error('Tron wallet not available:', error.message) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
| {% endcode %} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Always use `try/catch` blocks when initializing sessions or accessing dynamic features. | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| ## Memory Management | ||||||||||||||||||||
|
|
||||||||||||||||||||
| For security, you should clear sensitive data from memory when a session is complete. The WDK provided a `.dispose()` method for this purpose. | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| ### Disposing the Instance | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Calling `dispose()` clears the seed phrase and private keys derived in memory. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| {% code title="Dispose WDK" lineNumbers="true" %} | ||||||||||||||||||||
| ```typescript | ||||||||||||||||||||
| function endSession(wdk) { | ||||||||||||||||||||
| // 1. Clean up sensitive data | ||||||||||||||||||||
| wdk.dispose() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // 2. Modify app state to reflect logged-out status | ||||||||||||||||||||
| // ... | ||||||||||||||||||||
|
|
||||||||||||||||||||
| console.log('Session ended, wallet data cleared.') | ||||||||||||||||||||
| } | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
| {% endcode %} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| {% hint style="warning" %} | ||||||||||||||||||||
| **After Disposal:** Once disposed, any attempt to use the `wdk` instance or its derived accounts will result in an error. You must inspect a new instance to resume operations. | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inspect a new instance? Do you mean instantiate? |
||||||||||||||||||||
| {% endhint %} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ## Security Best Practices | ||||||||||||||||||||
|
|
||||||||||||||||||||
| * **Environment Variables:** Never hardcode API keys or seed phrases in your source code. Use environment variables (e.g., `process.env.TON_API_KEY`). | ||||||||||||||||||||
| * **Secure Storage:** If persisting a session, never store the raw seed phrase in local storage. Use secure operating system storage (like Keychain on macOS or Keystore on Android). | ||||||||||||||||||||
|
Comment on lines
+73
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --- | ||
| title: Install WDK Core | ||
| description: Learn how to install and set up the WDK Core module. | ||
| layout: | ||
| width: default | ||
| title: | ||
| visible: true | ||
| description: | ||
| visible: true | ||
| tableOfContents: | ||
| visible: true | ||
| outline: | ||
| visible: true | ||
| pagination: | ||
| visible: false | ||
| metadata: | ||
| visible: false | ||
| --- | ||
|
|
||
| # Install WDK Core | ||
|
|
||
| This guide shows you how to install the `@tetherto/wdk` package, which serves as the main entry point for the Wallet Development Kit (WDK). | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please a link to the package |
||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before you begin, ensure you have the following installed: | ||
|
|
||
| * **Node.js**: version 18 or higher. | ||
| * **npm**: usually comes with Node.js. | ||
|
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add links to node and npm |
||
|
|
||
| ## Installation | ||
|
|
||
| To install the WDK Core package, run the following command in your terminal: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a link to the package |
||
|
|
||
| ```bash | ||
| npm install @tetherto/wdk | ||
| ``` | ||
|
|
||
| This package allows you to manage different blockchain wallets and protocols through a single interface. | ||
|
|
||
| ## Next steps | ||
|
|
||
| Now that you have installed the core package, you can [instantiate the WDK](./instantiation.md) to start creating wallets. | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,73 @@ | ||||||||||
| --- | ||||||||||
| title: Instantiate WDK | ||||||||||
| description: Learn how to create a new WDK instance. | ||||||||||
| layout: | ||||||||||
| width: default | ||||||||||
| title: | ||||||||||
| visible: true | ||||||||||
| description: | ||||||||||
| visible: true | ||||||||||
| tableOfContents: | ||||||||||
| visible: true | ||||||||||
| outline: | ||||||||||
| visible: true | ||||||||||
| pagination: | ||||||||||
| visible: false | ||||||||||
| metadata: | ||||||||||
| visible: false | ||||||||||
| --- | ||||||||||
|
|
||||||||||
| # Instantiate WDK | ||||||||||
|
|
||||||||||
| This guide explains how to import the WDK Core module and create a new instance to start managing your wallets. | ||||||||||
|
|
||||||||||
| ## Import the module | ||||||||||
|
|
||||||||||
| First, import the `WDK` class from the package you installed: | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a link to the installation guide |
||||||||||
|
|
||||||||||
| {% code title="Import WDK Core"lineNumbers="true" %} | ||||||||||
| ```typescript | ||||||||||
| import WDK from '@tetherto/wdk' | ||||||||||
| ``` | ||||||||||
| {% endcode %} | ||||||||||
|
|
||||||||||
| ## Create an Instance | ||||||||||
|
|
||||||||||
| To use the SDK, you must create an instance of the `WDK` class. This instance acts as the central manager for all your wallets and protocols. | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| You can initialize `WDK` in two ways: with a new seed phrase or an existing one. | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add links to the headers |
||||||||||
|
|
||||||||||
| ### Option 1: Generate a new wallet | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| If you are creating a fresh wallet for a user, use the static `getRandomSeedPhrase()` method to generate a secure mnemonic. | ||||||||||
|
|
||||||||||
| {% code title="Create new WDK Instance" lineNumbers="true" %} | ||||||||||
| ```typescript | ||||||||||
| // 1. Generate a secure random seed phrase | ||||||||||
| const seedPhrase = WDK.getRandomSeedPhrase() | ||||||||||
|
|
||||||||||
| // 2. Initialize the WDK instance with the new seed | ||||||||||
| const wdk = new WDK(seedPhrase) | ||||||||||
| ``` | ||||||||||
| {% endcode %} | ||||||||||
|
|
||||||||||
| {% hint style="danger" %} | ||||||||||
| **Secure the Seed Phrase:** You must securely store this seed phrase immediately. If it is lost, the user will permanently lose access to their funds. | ||||||||||
| {% endhint %} | ||||||||||
|
|
||||||||||
| ### Option 2: Restore an existing wallet | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or
Suggested change
|
||||||||||
|
|
||||||||||
| If a user already has a seed phrase (e.g., from a previous session or another wallet), you can pass it directly to the constructor. | ||||||||||
|
|
||||||||||
| {% code title="Restore WDK Instance" lineNumbers="true" %} | ||||||||||
| ```typescript | ||||||||||
| // Replace this string with the user's actual seed phrase | ||||||||||
| const existingSeed = 'witch collapse practice feed shame open despair creek road again ice ...' | ||||||||||
|
|
||||||||||
| const wdk = new WDK(existingSeed) | ||||||||||
| ``` | ||||||||||
| {% endcode %} | ||||||||||
|
|
||||||||||
| ## Next steps | ||||||||||
|
|
||||||||||
| With your WDK instance ready, you can now [register wallet modules](./wallet-registration.md) to interact with specific blockchains like Ethereum, TON, or Bitcoin. | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a link to the respective wallet modules. |
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge installation and Instantiation into one.
Installation does not provide enough value.
Also use a more readable name like "Get Started" or similar