From 6a6eda696cc17f12e0ece8e5b30346771c8bcb97 Mon Sep 17 00:00:00 2001 From: jinoosss <112360739+jinoosss@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:01:15 +0900 Subject: [PATCH] docs: update Readme (#11) --- README.md | 256 ++++++++++++++++++++++++++++++++++++----- packages/sdk/README.md | 256 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 458 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 8ab1062..13bcf95 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,242 @@ # Adena Wallet SDK -## Adena Wallet SDK allows dapps to connect to Adena Wallet +The Adena Wallet SDK is a TypeScript-based library designed to interact with the Adena Wallet and TM2 Wallet. -1. Adena Wallet - - [Docs](https://docs.adena.app) - - [Extension](https://www.adena.app/) +This SDK provides various functionalities, including wallet connection, network switching, transaction signing, and more. -### Installing Adena Wallet SDK +## Adena Wallet -1. Check available versions: +- [Docs](https://docs.adena.app) +- [Extension](https://www.adena.app/) - ```shell - # yarn - yarn info @adena-wallet/sdk versions +## Installation - # npm - npm view @adena-wallet/sdk versions - ``` +Install the SDK via npm: -2. Install latest version: +``` +npm install @adena-wallet/sdk +``` + +Or via yarn: + +``` +yarn add @adena-wallet/sdk +``` + +## Basic Usage + +Here is a basic example of how to use the SDK: + +``` +import { AdenaSDK, WalletProvider } from '@adena-wallet/sdk'; + +const walletProvider = new WalletProvider(); +const adenaSDK = new AdenaSDK(walletProvider); + +// Connect to the wallet +adenaSDK.connectWallet().then(() => { + console.log('Wallet connected'); +}); + +// Retrieves account information +adenaSDK.getAccount().then((account) => { + console.log('Account:', account); +}); +``` + +## SDK Functions + +### `connectWallet` + +Connects the SDK to the wallet. + +**Example:** + +``` +adenaSDK.connectWallet().then(() => { + console.log('Wallet connected'); +}); +``` + +### `disconnectWallet` + +Disconnects the SDK from the wallet. + +**Example:** + +``` +adenaSDK.disconnectWallet(); +``` + +### `getConnectionState` + +Retrieves the current connection state of the wallet. + +**Example:** + +``` +const state = adenaSDK.getConnectionState(); +console.log('Connection state:', state); +``` + +### `onConnectionChange` + +Sets up a listener for connection state changes. + +**Example:** + +``` +adenaSDK.onConnectionChange({ + callback: (event) => { + console.log('Connection event:', event); + }, +}); +``` + +### `offConnectionChange` + +Removes a previously set connection state change listener. + +**Example:** + +``` +const listener = (event) => { + console.log('Connection event:', event); +}; + +adenaSDK.onConnectionChange({ callback: listener }); + +// Later, remove the listener +adenaSDK.offConnectionChange({ callback: listener }); +``` + +### `isConnected` + +Checks if the wallet is currently connected. + +**Example:** + +``` +adenaSDK.isConnected().then((response) => { + console.log('Is connected:', response.status); +}); +``` + +### `getAccount` + +Retrieves account information from the connected wallet. + +**Example:** + +``` +adenaSDK.getAccount().then((account) => { + console.log('Account:', account); +}); +``` + +### `switchNetwork` + +Switches the wallet to a different network. + +**Example:** + +``` +adenaSDK.switchNetwork({ chainId: 'new-chain-id' }).then(() => { + console.log('Network switched'); +}); +``` + +### `addNetwork` + +Adds a new network to the wallet. + +**Example:** + +``` +adenaSDK.addNetwork({ + chainId: 'new-chain-id', + chainName: 'New Network', + rpcUrl: 'New Chain RPC URL', +}).then(() => { + console.log('Network added'); +}); +``` + +### `signTransaction` + +Signs a transaction with the connected wallet. + +**Example:** + +``` +const tx = { + /** specific message types */ + messages: Any[]; + /** transaction costs (fee) */ + fee?: TxFee; + /** the signatures for the transaction */ + signatures: TxSignature[]; + /** memo attached to the transaction */ + memo: string; +}; + +adenaSDK.signTransaction({ tx }).then((response) => { + console.log('Signed transaction:', response.encodedTransaction); +}); +``` + +### `broadcastTransaction` - ```shell - # yarn - yarn add @adena-wallet/sdk +Broadcasts a signed transaction to the network. - # npm - npm install @adena-wallet/sdk - ``` +**Example:** -3. Check installed version: +``` +const tx = { + /** specific message types */ + messages: Any[]; + /** transaction costs (fee) */ + fee?: TxFee; + /** the signatures for the transaction */ + signatures: TxSignature[]; + /** memo attached to the transaction */ + memo: string; +}; + +adenaSDK.broadcastTransaction({ tx }).then((response) => { + console.log('Broadcast response:', response); +}); +``` - ```shell - # yarn - yarn list @adena-wallet/sdk +### `onChangeAccount` - # npm - npm list @adena-wallet/sdk - ``` +Sets up a listener for account changes. -### Development Setup +**Example:** + +``` +adenaSDK.onChangeAccount({ + callback: (account) => { + console.log('Account changed:', account); + }, +}); +``` + +### `onChangeNetwork` + +Sets up a listener for network changes. + +**Example:** + +``` +adenaSDK.onChangeNetwork({ + callback: (network) => { + console.log('Network changed:', network); + }, +}); +``` + +## Development Setup The Node.js version is 18.14.2. We recommend using [nvm](https://github.com/nvm-sh/nvm). @@ -49,3 +247,7 @@ We recommend using [nvm](https://github.com/nvm-sh/nvm). $ nvm use ``` + +## License + +This project is licensed under the MIT License. diff --git a/packages/sdk/README.md b/packages/sdk/README.md index 8ab1062..13bcf95 100644 --- a/packages/sdk/README.md +++ b/packages/sdk/README.md @@ -1,44 +1,242 @@ # Adena Wallet SDK -## Adena Wallet SDK allows dapps to connect to Adena Wallet +The Adena Wallet SDK is a TypeScript-based library designed to interact with the Adena Wallet and TM2 Wallet. -1. Adena Wallet - - [Docs](https://docs.adena.app) - - [Extension](https://www.adena.app/) +This SDK provides various functionalities, including wallet connection, network switching, transaction signing, and more. -### Installing Adena Wallet SDK +## Adena Wallet -1. Check available versions: +- [Docs](https://docs.adena.app) +- [Extension](https://www.adena.app/) - ```shell - # yarn - yarn info @adena-wallet/sdk versions +## Installation - # npm - npm view @adena-wallet/sdk versions - ``` +Install the SDK via npm: -2. Install latest version: +``` +npm install @adena-wallet/sdk +``` + +Or via yarn: + +``` +yarn add @adena-wallet/sdk +``` + +## Basic Usage + +Here is a basic example of how to use the SDK: + +``` +import { AdenaSDK, WalletProvider } from '@adena-wallet/sdk'; + +const walletProvider = new WalletProvider(); +const adenaSDK = new AdenaSDK(walletProvider); + +// Connect to the wallet +adenaSDK.connectWallet().then(() => { + console.log('Wallet connected'); +}); + +// Retrieves account information +adenaSDK.getAccount().then((account) => { + console.log('Account:', account); +}); +``` + +## SDK Functions + +### `connectWallet` + +Connects the SDK to the wallet. + +**Example:** + +``` +adenaSDK.connectWallet().then(() => { + console.log('Wallet connected'); +}); +``` + +### `disconnectWallet` + +Disconnects the SDK from the wallet. + +**Example:** + +``` +adenaSDK.disconnectWallet(); +``` + +### `getConnectionState` + +Retrieves the current connection state of the wallet. + +**Example:** + +``` +const state = adenaSDK.getConnectionState(); +console.log('Connection state:', state); +``` + +### `onConnectionChange` + +Sets up a listener for connection state changes. + +**Example:** + +``` +adenaSDK.onConnectionChange({ + callback: (event) => { + console.log('Connection event:', event); + }, +}); +``` + +### `offConnectionChange` + +Removes a previously set connection state change listener. + +**Example:** + +``` +const listener = (event) => { + console.log('Connection event:', event); +}; + +adenaSDK.onConnectionChange({ callback: listener }); + +// Later, remove the listener +adenaSDK.offConnectionChange({ callback: listener }); +``` + +### `isConnected` + +Checks if the wallet is currently connected. + +**Example:** + +``` +adenaSDK.isConnected().then((response) => { + console.log('Is connected:', response.status); +}); +``` + +### `getAccount` + +Retrieves account information from the connected wallet. + +**Example:** + +``` +adenaSDK.getAccount().then((account) => { + console.log('Account:', account); +}); +``` + +### `switchNetwork` + +Switches the wallet to a different network. + +**Example:** + +``` +adenaSDK.switchNetwork({ chainId: 'new-chain-id' }).then(() => { + console.log('Network switched'); +}); +``` + +### `addNetwork` + +Adds a new network to the wallet. + +**Example:** + +``` +adenaSDK.addNetwork({ + chainId: 'new-chain-id', + chainName: 'New Network', + rpcUrl: 'New Chain RPC URL', +}).then(() => { + console.log('Network added'); +}); +``` + +### `signTransaction` + +Signs a transaction with the connected wallet. + +**Example:** + +``` +const tx = { + /** specific message types */ + messages: Any[]; + /** transaction costs (fee) */ + fee?: TxFee; + /** the signatures for the transaction */ + signatures: TxSignature[]; + /** memo attached to the transaction */ + memo: string; +}; + +adenaSDK.signTransaction({ tx }).then((response) => { + console.log('Signed transaction:', response.encodedTransaction); +}); +``` + +### `broadcastTransaction` - ```shell - # yarn - yarn add @adena-wallet/sdk +Broadcasts a signed transaction to the network. - # npm - npm install @adena-wallet/sdk - ``` +**Example:** -3. Check installed version: +``` +const tx = { + /** specific message types */ + messages: Any[]; + /** transaction costs (fee) */ + fee?: TxFee; + /** the signatures for the transaction */ + signatures: TxSignature[]; + /** memo attached to the transaction */ + memo: string; +}; + +adenaSDK.broadcastTransaction({ tx }).then((response) => { + console.log('Broadcast response:', response); +}); +``` - ```shell - # yarn - yarn list @adena-wallet/sdk +### `onChangeAccount` - # npm - npm list @adena-wallet/sdk - ``` +Sets up a listener for account changes. -### Development Setup +**Example:** + +``` +adenaSDK.onChangeAccount({ + callback: (account) => { + console.log('Account changed:', account); + }, +}); +``` + +### `onChangeNetwork` + +Sets up a listener for network changes. + +**Example:** + +``` +adenaSDK.onChangeNetwork({ + callback: (network) => { + console.log('Network changed:', network); + }, +}); +``` + +## Development Setup The Node.js version is 18.14.2. We recommend using [nvm](https://github.com/nvm-sh/nvm). @@ -49,3 +247,7 @@ We recommend using [nvm](https://github.com/nvm-sh/nvm). $ nvm use ``` + +## License + +This project is licensed under the MIT License.