@hashgraph/hedera-wallet-connect 1.5.2-canary.8dde86c.0 → 1.5.2-canary.90511fb.0
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/README.md +232 -64
- package/dist/lib/shared/utils.d.ts +2 -1
- package/dist/lib/shared/utils.js +3 -2
- package/package.json +4 -17
package/README.md
CHANGED
@@ -1,70 +1,238 @@
|
|
1
|
-
#
|
1
|
+
# Background
|
2
|
+
|
3
|
+
This library provides tools and recommendations on how to integrate Hedera into an application
|
4
|
+
that requires communication with a wallet that supports Hedera. There are 2 different paths to
|
5
|
+
integrate Hedera in this context. Both approaches use the
|
6
|
+
[WalletConnect](https://walletconnect.network/) network to send messages from apps to wallets
|
7
|
+
and back.
|
8
|
+
|
9
|
+
## Hedera APIs
|
10
|
+
|
11
|
+
Hedera natively operates using a gRPC API for write transactions and by default, a REST API for
|
12
|
+
read transactions. Hedera implements EVM compatible smart contracts using
|
13
|
+
[Hyperledger Besu](https://besu.hyperledger.org/) under the hood.
|
14
|
+
|
15
|
+
Ethereum developers and toolsets often expect to interact with Ethereum compatible chains using
|
16
|
+
the [Ethereum JSON-RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/). To acheive
|
17
|
+
compatibility with this API,
|
18
|
+
[Hedera JSON-RPC Providers](https://docs.hedera.com/hedera/core-concepts/smart-contracts/json-rpc-relay#community-hosted-json-rpc-relays)
|
19
|
+
operate a software middlelayer that translates Ethereum JSON-RPC compatible API calls into
|
20
|
+
Hedera gRPC and REST API calls.
|
2
21
|
|
3
|
-
|
4
|
-
WalletConnect ecosystem and vice versa.
|
22
|
+
## Ethereum JSON-RPC vs. Hedera JSON-RPC vs. Hedera JSON-RPC Relay
|
5
23
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Hedera context.
|
24
|
+
When integrating, app developers can choose to use the Hedera native approach and send
|
25
|
+
transactions to wallets over the WalletConnect network using the JSON-RPC spec defined for
|
26
|
+
Hedera native transactions or use Ethereum JSON-RPC calls sent to a Hedera JSON-RPC Relay
|
27
|
+
provider which then communicates with Hedera consensus and mirror nodes.
|
11
28
|
|
12
|
-
|
29
|
+
On a high level, JSON-RPC is a type of API stucture, such as SOAP, gRPC, REST, GraphQL, etc. In
|
30
|
+
the Hedera ecosystem, there are distinct concepts regarding JSON-RPC APIs to consider:
|
13
31
|
|
14
|
-
-
|
15
|
-
-
|
32
|
+
- Ethereum JSON-RPC spec defines how to interact with Ethereum compatible networks
|
33
|
+
- Hedera JSON-RPC Relay implements the Ethereum JSON-RPC spec for Hedera
|
34
|
+
- Wallets in the Hedera ecosystem also support a separate specification that defines how to send
|
35
|
+
transactions and messages to wallets over the WalletConnect network without relying on a
|
36
|
+
Hedera JSON-RPC Relay provider. This is a Hedera specific specification defined for utilizing
|
37
|
+
the WalletConnect network distict from other JSON-RPC specs such as the one defined by the
|
38
|
+
Ethereum network.
|
16
39
|
|
17
|
-
|
18
|
-
> and interact.
|
19
|
-
>
|
20
|
-
> -- <cite> https://walletconnect.com
|
40
|
+
For more information see:
|
21
41
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
[
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
42
|
+
- [Ethereum JSON-RPC Specification ](https://ethereum.github.io/execution-apis/api-documentation/)
|
43
|
+
- [Hedera JSON-RPC relay](https://docs.hedera.com/hedera/core-concepts/smart-contracts/json-rpc-relay)
|
44
|
+
- [Hedera Native JSON-RPC spec for WalletConnect](https://docs.reown.com/advanced/multichain/rpc-reference/hedera-rpc)
|
45
|
+
- [Hedera Javascript SDK](https://www.npmjs.com/package/@hashgraph/sdk)
|
46
|
+
- [Reown Docs](https://docs.reown.com/overview)
|
47
|
+
- [WalletConnect Network](https://walletconnect.network/)
|
48
|
+
|
49
|
+
# Getting started
|
50
|
+
|
51
|
+
In addition to choosing between the Hedera native JSON-RPC spec and the Ethereum JSON-RPC spec,
|
52
|
+
when building with javascript/typescript, there are 2 supported options to utilize the
|
53
|
+
WalletConnect network to send information from apps to wallets and back.
|
54
|
+
|
55
|
+
This README assumes an understanding of Hedera as well as the WalletConnect network and focusses
|
56
|
+
on how to send a payload to a wallet for processing and presentation to an end user that is a
|
57
|
+
Hedera account holder. We recommend reviewing the [Hedera Docs](https://docs.hedera.com/) and
|
58
|
+
first submitting transactions directly to the Hedera network without requiring interaction with
|
59
|
+
a [Wallet](#hedera-wallets) when integrating Hedera for the first time. We also recommend
|
60
|
+
reviewing the [Reown docs](https://docs.reown.com/overview).
|
61
|
+
|
62
|
+
## Using this library and underlying WalletConnect libraries directly
|
63
|
+
|
64
|
+
1. Add Hedera dependencies to your project:
|
65
|
+
|
66
|
+
```sh
|
67
|
+
npm install @hashgraph/hedera-wallet-connect@2.0.0-canary.811af2f.0 @hashgraph/sdk @walletconnect/modal
|
68
|
+
```
|
69
|
+
|
70
|
+
2. Initialize dApp Connector
|
71
|
+
|
72
|
+
```typescript
|
73
|
+
import {
|
74
|
+
HederaSessionEvent,
|
75
|
+
HederaJsonRpcMethod,
|
76
|
+
DAppConnector,
|
77
|
+
HederaChainId,
|
78
|
+
} from '@hashgraph/hedera-wallet-connect'
|
79
|
+
import { LedgerId } from '@hashgraph/sdk'
|
80
|
+
|
81
|
+
const metadata = {
|
82
|
+
name: 'Hedera Integration using Hedera DAppConnector - v1 approach',
|
83
|
+
description: 'Hedera dAppConnector Example',
|
84
|
+
url: 'https://example.com', // origin must match your domain & subdomain
|
85
|
+
icons: ['https://avatars.githubusercontent.com/u/31002956'],
|
86
|
+
}
|
87
|
+
|
88
|
+
const dAppConnector = new DAppConnector(
|
89
|
+
metadata,
|
90
|
+
LedgerId.Mainnet,
|
91
|
+
projectId,
|
92
|
+
Object.values(HederaJsonRpcMethod),
|
93
|
+
[HederaSessionEvent.ChainChanged, HederaSessionEvent.AccountsChanged],
|
94
|
+
[HederaChainId.Mainnet, HederaChainId.Testnet],
|
95
|
+
)
|
96
|
+
|
97
|
+
await dAppConnector.init({ logger: 'error' })
|
98
|
+
```
|
99
|
+
|
100
|
+
3. Connect to a wallet
|
101
|
+
|
102
|
+
```typescript
|
103
|
+
await dAppConnector.openModal()
|
104
|
+
```
|
105
|
+
|
106
|
+
4. Handle sessions, events, and payloads.
|
107
|
+
|
108
|
+
- See: [DAppConnector](./src/lib/dapp/index.ts)
|
109
|
+
|
110
|
+
### Examples, demos, and tools
|
111
|
+
|
112
|
+
- [Hashgraph React Wallets by Buidler Labs](https://github.com/buidler-labs/hashgraph-react-wallets)
|
113
|
+
- [Hashgraph Online's WalletConnect SDK](https://github.com/hashgraph-online/hashinal-wc)
|
114
|
+
- <em>[Add an example, demo, or tool here](https://github.com/hashgraph/hedera-wallet-connect/pulls)</em>
|
115
|
+
|
116
|
+
## Using Reown's AppKit
|
117
|
+
|
118
|
+
1. Follow one of the quickstart instructions at
|
119
|
+
https://docs.reown.com/appkit/overview#quickstart
|
120
|
+
|
121
|
+
2. Add Hedera dependencies to your project:
|
122
|
+
|
123
|
+
```sh
|
124
|
+
npm install @hashgraph/hedera-wallet-connect@2.0.1-canary.24fffa7.0 @hashgraph/sdk @walletconnect/universal-provider
|
125
|
+
```
|
126
|
+
|
127
|
+
3. Update `createAppKit` with adapters and a universal provider for Hedera. Note the
|
128
|
+
HederaAdapter will need to come before the WagmiAdapter in the adapters array.
|
129
|
+
|
130
|
+
```typescript
|
131
|
+
import type UniversalProvider from '@walletconnect/universal-provider'
|
132
|
+
|
133
|
+
import {
|
134
|
+
HederaProvider,
|
135
|
+
HederaAdapter,
|
136
|
+
HederaChainDefinition,
|
137
|
+
hederaNamespace,
|
138
|
+
} from '@hashgraph/hedera-wallet-connect'
|
139
|
+
|
140
|
+
const metadata = {
|
141
|
+
name: 'AppKit w/ Hedera',
|
142
|
+
description: 'Hedera AppKit Example',
|
143
|
+
url: 'https://example.com', // origin must match your domain & subdomain
|
144
|
+
icons: ['https://avatars.githubusercontent.com/u/179229932']
|
145
|
+
}
|
146
|
+
|
147
|
+
const hederaEVMAdapter = new HederaAdapter({
|
148
|
+
projectId,
|
149
|
+
networks: [
|
150
|
+
HederaChainDefinition.EVM.Mainnet,
|
151
|
+
HederaChainDefinition.EVM.Testnet,
|
152
|
+
],
|
153
|
+
namespace: 'eip155',
|
154
|
+
})
|
155
|
+
|
156
|
+
const universalProvider = (await HederaProvider.init({
|
157
|
+
projectId: "YOUR_PROJECT_ID"
|
158
|
+
metadata,
|
159
|
+
})) as unknown as UniversalProvider, // avoid type mismatch error due to missing of private properties in HederaProvider
|
160
|
+
|
161
|
+
// ...
|
162
|
+
createAppKit({
|
163
|
+
adapters: [ hederaEVMAdapter ],
|
164
|
+
//@ts-expect-error expected type error
|
165
|
+
universalProvider,
|
166
|
+
projectId,
|
167
|
+
metadata,
|
168
|
+
networks: [
|
169
|
+
// EVM
|
170
|
+
HederaChainDefinition.EVM.Mainnet,
|
171
|
+
HederaChainDefinition.EVM.Testnet,
|
172
|
+
],
|
173
|
+
})
|
174
|
+
|
175
|
+
// ...
|
176
|
+
```
|
177
|
+
|
178
|
+
4. Recommended: Add Hedera Native WalletConnect Adapter
|
179
|
+
|
180
|
+
```typescript
|
181
|
+
import { HederaChainDefinition, hederaNamespace } from '@hashgraph/hedera-wallet-connect'
|
182
|
+
|
183
|
+
// ...
|
184
|
+
|
185
|
+
const hederaNativeAdapter = new HederaAdapter({
|
186
|
+
projectId,
|
187
|
+
networks: [HederaChainDefinition.Native.Mainnet, HederaChainDefinition.Native.Testnet],
|
188
|
+
namespace: hederaNamespace, // 'hedera' as CaipNamespace,
|
189
|
+
})
|
190
|
+
|
191
|
+
// ...
|
192
|
+
|
193
|
+
createAppKit({
|
194
|
+
adapters: [hederaEVMAdapter, hederaNativeAdapter],
|
195
|
+
projectId,
|
196
|
+
metadata,
|
197
|
+
networks: [
|
198
|
+
// EVM
|
199
|
+
HederaChainDefinition.EVM.Mainnet,
|
200
|
+
HederaChainDefinition.EVM.Testnet,
|
201
|
+
// Native
|
202
|
+
HederaChainDefinition.Native.Mainnet,
|
203
|
+
HederaChainDefinition.Native.Testnet,
|
204
|
+
],
|
205
|
+
})
|
206
|
+
```
|
207
|
+
|
208
|
+
### Examples, demos, and tools
|
209
|
+
|
210
|
+
- [Hedera App Example by Hgraph](https://github.com/hgraph-io/hedera-app)
|
211
|
+
- [Hedera Wallet Example by Hgraph](https://github.com/hgraph-io/hedera-wallet)
|
212
|
+
- <em>[Add an example, demo, or tool here](https://github.com/hashgraph/hedera-wallet-connect/pulls)</em>
|
213
|
+
|
214
|
+
# Hedera Wallets
|
215
|
+
|
216
|
+
- [Hashpack](https://hashpack.app/)
|
217
|
+
- [Kabila](https://wallet.kabila.app/)
|
218
|
+
- [Blade](https://bladewallet.io/)
|
219
|
+
- [Dropp](https://dropp.cc/)
|
220
|
+
|
221
|
+
# Upgrading from v1 to v2
|
222
|
+
|
223
|
+
Upgrading from v1 to v2 should be fairly straightforward. We have maintained compatibility with
|
224
|
+
the v1 structure, while deprecating a few methods marked as deprecated. The v1 library did not
|
225
|
+
explicitly offer support for Ethereum JSON-RPC function calls, so the only breaking changes
|
226
|
+
refer to how to send transactions to wallets using the `hedera:(mainnet|testnet)` namespace.
|
227
|
+
While minimal, the main breaking changes are:
|
228
|
+
|
229
|
+
- remove WalletConnect v1 modals
|
230
|
+
|
231
|
+
- these are very old, though in the spirit of semver, we kept the dependency until this
|
232
|
+
library's v2 release
|
233
|
+
|
234
|
+
- remove setting node id's within this library for transactions
|
235
|
+
|
236
|
+
- initially, a transaction created by the Hedera Javascript SDK needed to have one or more
|
237
|
+
consensus node ids set to be able to serialize into bytes, sent over a network, and
|
238
|
+
deserialized by the SDK
|
@@ -30,9 +30,10 @@ export declare function transactionToBase64String<T extends Transaction>(transac
|
|
30
30
|
export declare function base64StringToTransaction<T extends Transaction>(transactionBytes: string): T;
|
31
31
|
/**
|
32
32
|
* @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
|
33
|
+
* @param nodeAccountId - an optional `AccountId` to set the node account ID for the transaction
|
33
34
|
* @returns `string`
|
34
35
|
* */
|
35
|
-
export declare function transactionToTransactionBody<T extends Transaction>(transaction: T):
|
36
|
+
export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId?: AccountId | null): proto.ITransactionBody;
|
36
37
|
export declare function transactionBodyToBase64String(transactionBody: proto.ITransactionBody): string;
|
37
38
|
/**
|
38
39
|
* @param transactionList - a proto.TransactionList object
|
package/dist/lib/shared/utils.js
CHANGED
@@ -55,12 +55,13 @@ export function base64StringToTransaction(transactionBytes) {
|
|
55
55
|
}
|
56
56
|
/**
|
57
57
|
* @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
|
58
|
+
* @param nodeAccountId - an optional `AccountId` to set the node account ID for the transaction
|
58
59
|
* @returns `string`
|
59
60
|
* */
|
60
|
-
export function transactionToTransactionBody(transaction) {
|
61
|
+
export function transactionToTransactionBody(transaction, nodeAccountId = null) {
|
61
62
|
// This is a private function, though provides the capabilities to construct a proto.TransactionBody
|
62
63
|
//@ts-ignore
|
63
|
-
return transaction._makeTransactionBody(
|
64
|
+
return transaction._makeTransactionBody(nodeAccountId);
|
64
65
|
}
|
65
66
|
export function transactionBodyToBase64String(transactionBody) {
|
66
67
|
return Uint8ArrayToBase64String(proto.TransactionBody.encode(transactionBody).finish());
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hashgraph/hedera-wallet-connect",
|
3
|
-
"version": "1.5.2-canary.
|
3
|
+
"version": "1.5.2-canary.90511fb.0",
|
4
4
|
"description": "A library to facilitate integrating Hedera with WalletConnect",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -22,8 +22,8 @@
|
|
22
22
|
"@hashgraph/hedera-wallet-connect": "^1.5.0",
|
23
23
|
"@swc/core": "^1.7.40",
|
24
24
|
"@swc/jest": "^0.2.36",
|
25
|
-
"@types/jest": "^
|
26
|
-
"@types/node": "^
|
25
|
+
"@types/jest": "^30.0.0",
|
26
|
+
"@types/node": "^24.0.3",
|
27
27
|
"@types/react-dom": "^19.0.3",
|
28
28
|
"@walletconnect/modal": "^2.7.0",
|
29
29
|
"@walletconnect/sign-client": "^2.19.1",
|
@@ -32,9 +32,7 @@
|
|
32
32
|
"esbuild": "^0.25.0",
|
33
33
|
"esbuild-plugin-copy": "^2.1.1",
|
34
34
|
"eslint-plugin-tsdoc": "^0.4.0",
|
35
|
-
"
|
36
|
-
"jest": "^29.7.0",
|
37
|
-
"lint-staged": "^15.1.0",
|
35
|
+
"jest": "^30.0.0",
|
38
36
|
"lokijs": "^1.5.12",
|
39
37
|
"long": "^5.2.3",
|
40
38
|
"nodemon": "^3.0.3",
|
@@ -44,29 +42,18 @@
|
|
44
42
|
"rimraf": "^5.0.5",
|
45
43
|
"ts-node": "^10.9.2",
|
46
44
|
"tweetnacl": "^1.0.3",
|
47
|
-
"typedoc": "^0.27.6",
|
48
|
-
"typedoc-theme-hierarchy": "^5.0.0",
|
49
45
|
"typescript": "^5.2.2"
|
50
46
|
},
|
51
47
|
"scripts": {
|
52
48
|
"build": "rimraf dist && tsc",
|
53
|
-
"build:ts-demo": "node scripts/demos/typescript/build.mjs",
|
54
|
-
"build:react-demo": "node scripts/demos/react/build.mjs",
|
55
|
-
"build:docs": "typedoc --options typedoc.json",
|
56
49
|
"watch": "nodemon --watch src/lib/ --ext ts --exec \"npm run build\"",
|
57
|
-
"dev": "npm run dev:ts-demo",
|
58
|
-
"dev:docs": "cd docs && npm run start",
|
59
|
-
"dev:ts-demo": "rimraf dist && npm run build && concurrently --raw \"npm run watch\" \"node scripts/demos/typescript/dev.mjs\"",
|
60
|
-
"dev:react-demo": "rimraf dist && npm run build && concurrently --raw \"npm run watch\" \"node scripts/demos/react/dev.mjs\"",
|
61
50
|
"test": "jest",
|
62
51
|
"test:watch": "jest --watch",
|
63
52
|
"test:connect": "jest --testMatch '**/DAppConnector.test.ts' --verbose",
|
64
53
|
"test:signer": "jest --testMatch '**/DAppSigner.test.ts' --verbose",
|
65
54
|
"prepublishOnly": "rm -Rf dist && npm run build",
|
66
|
-
"prepare": "husky install",
|
67
55
|
"prettier:check": "prettier --check ./src/",
|
68
56
|
"prettier:fix": "prettier --write ./src/",
|
69
|
-
"prod:docs-docker": "sh docker-run.sh",
|
70
57
|
"test:sigMap": "jest --testMatch '**/SignatureMapHelpers.test.ts' --verbose",
|
71
58
|
"test:coverage": "jest --coverage",
|
72
59
|
"test:coverage:html": "jest --coverage --coverageReporters='text-summary' --coverageReporters='html'"
|