Skip to content

Commit

Permalink
Add getUserWalletAddress SDK method
Browse files Browse the repository at this point in the history
  • Loading branch information
milukove committed Jul 4, 2024
1 parent 8ec822a commit 36ad94b
Show file tree
Hide file tree
Showing 102 changed files with 666 additions and 181 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Grindery Wallet SDK Changelog

## v0.4.0 (2024-07-05)

### Features

- Added `getUserWalletAddress` SDK method, allowing to silently exchange Telegram user ID to EVM wallet address

## v0.3.0 (2024-06-18)

### Added support for BNB and opBNB chains
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The SDK enables your dapp to provide a seamless user experience for Grindery use
- [Basic usage](#basic-usage)
- [Server connection](#server-connection)
- [Wallet connection](#wallet-connection)
- [Silently getting wallet address](#silently-getting-wallet-address)
- [Sending transactions](#sending-transactions)
- [Signing](#signing)
- [Chain switching](#chain-switching)
Expand Down Expand Up @@ -172,6 +173,31 @@ WalletSDK.on('disconnect', => {
WalletSDK.disconnect();
```

## Silently getting wallet address

The SDK allows dApps to exchange Telegram user ID to user's EVM wallet address.

The method doesn't require user to go through the [wallet connection process](#wallet-connection), and can be executed silently in the background. However, without fully connected wallet a dApp has read-only access, and can't request message signing or transactions sending. To do this ask user to connect the wallet first.

```typescript
WalletSDK.on('connect', async () => {
const userId = '123456';
const telegramUserWallet =
await window.Grindery.WalletSDK.getUserWalletAddress(userId);
});
```

This can be especially usefull for Telegram mini-apps, where user ID can be detected automatically. For example:

```typescript
WalletSDK.on('connect', async () => {
const telegramUserWallet =
await window.Grindery.WalletSDK.getUserWalletAddress(
window.Telegram?.WebApp?.initDataUnsafe?.user?.id
);
});
```

## Sending transactions

To request transaction sending use [`sendTransaction()`](https://grindery-io.github.io/grindery-wallet-sdk/classes/classes_WalletSDK.WalletSDK.html#sendTransaction) method, once the wallet is connected:
Expand Down
7 changes: 6 additions & 1 deletion dist/classes/Rpc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export declare enum RpcMethodNames {
waitForPairingResult = "waitForPairingResult",
request = "request",
waitForRequestResult = "waitForRequestResult",
'disconnect' = "disconnect"
'disconnect' = "disconnect",
getUserWalletAddress = "getUserWalletAddress"
}
/**
* @summary The Grindery RPC API request results
Expand Down Expand Up @@ -53,6 +54,10 @@ export declare namespace RpcRequestResults {
* @summary `disconnect` method result
*/
type disconnect = boolean;
/**
* @summary `getUserWalletAddress` method result
*/
type getUserWalletAddress = string;
}
/**
* @summary The Grindery RPC API wrapper class
Expand Down
9 changes: 9 additions & 0 deletions dist/classes/WalletSDK.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ProviderEventName } from './EventEmitter';
import { Provider } from './Provider';
import { RpcRequestResults } from './Rpc';
export type WalletSDKConfig = {
appId?: string;
};
Expand Down Expand Up @@ -81,6 +82,14 @@ export declare class WalletSDK {
* @returns {string} Returns chain id in CAIP-2 format
*/
getChain(): string;
/**
* @summary Exchange Telegram user ID to Grindery Wallet address
* @public
* @since 0.4.0
* @param {string} userId Telegram user ID
* @returns {Promise<string>} Grindery Wallet address
*/
getUserWalletAddress(userId: string): Promise<RpcRequestResults.getUserWalletAddress>;
/**
* @summary Adds a listener to the event
* @public
Expand Down
38 changes: 37 additions & 1 deletion dist/grindery-wallet-sdk.cjs.development.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/grindery-wallet-sdk.cjs.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/grindery-wallet-sdk.cjs.production.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/grindery-wallet-sdk.cjs.production.min.js.map

Large diffs are not rendered by default.

38 changes: 37 additions & 1 deletion dist/grindery-wallet-sdk.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/grindery-wallet-sdk.esm.js.map

Large diffs are not rendered by default.

38 changes: 37 additions & 1 deletion dist/grindery-wallet-sdk.umd.development.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/grindery-wallet-sdk.umd.development.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/grindery-wallet-sdk.umd.production.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/grindery-wallet-sdk.umd.production.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 36ad94b

Please sign in to comment.