@hashgraph/hedera-wallet-connect 2.0.1-canary.b1d8954.0 → 2.0.1-canary.d08bdc5.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 +132 -23
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,36 +1,119 @@
|
|
1
|
-
#
|
1
|
+
# Background
|
2
2
|
|
3
|
-
|
4
|
-
|
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.
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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.
|
21
|
+
|
22
|
+
## Ethereum JSON-RPC vs. Hedera JSON-RPC vs. Hedera JSON-RPC Relay
|
10
23
|
|
11
24
|
When integrating, app developers can choose to use the Hedera native approach and send
|
12
|
-
transactions to wallets over the WalletConnect
|
13
|
-
native transactions or use Ethereum JSON-RPC calls sent to a Hedera JSON-RPC provider
|
14
|
-
communicates with Hedera consensus and mirror nodes.
|
25
|
+
transactions to wallets over the WalletConnect network using the JSON-RPC spec defined for Hedera
|
26
|
+
native transactions or use Ethereum JSON-RPC calls sent to a Hedera JSON-RPC Relay provider
|
27
|
+
which then communicates with Hedera consensus and mirror nodes.
|
15
28
|
|
16
|
-
|
17
|
-
Hedera ecosystem, there are distinct concepts regarding JSON-RPC APIs to consider:
|
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:
|
18
31
|
|
19
32
|
- Ethereum JSON-RPC spec defines how to interact with Ethereum compatible networks
|
20
33
|
- Hedera JSON-RPC Relay implements the Ethereum JSON-RPC spec for Hedera
|
21
|
-
- Wallets in the Hedera ecosystem support a separate
|
22
|
-
transactions to wallets over the WalletConnect
|
23
|
-
|
24
|
-
network
|
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.
|
25
39
|
|
26
40
|
For more information see:
|
27
41
|
|
28
42
|
- [Ethereum JSON-RPC Specification ](https://ethereum.github.io/execution-apis/api-documentation/)
|
29
|
-
- [Hedera
|
30
|
-
- [Hedera Native
|
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)
|
31
45
|
- [@hashgraph/sdk](https://www.npmjs.com/package/@hashgraph/sdk)
|
32
46
|
|
33
|
-
|
47
|
+
# Getting started
|
48
|
+
|
49
|
+
In addition to choosing between the Hedera native JSON-RPC spec and the Ethereum JSON-RPC spec,
|
50
|
+
when building with javascript/typescript, there are 2 supported options to utilize the
|
51
|
+
WalletConnect network to send information from apps to wallets and back.
|
52
|
+
|
53
|
+
This README assumes a basic understanding of how to create transactions on Hedera as well as
|
54
|
+
handling sessions, payloads, and other transport layer details on the WalletConnect network and
|
55
|
+
focusses on how to send a payload to a wallet for processing and presentation to an end user
|
56
|
+
that is a Hedera account holder. We recommend reviewing the
|
57
|
+
[Hedera Docs](https://docs.hedera.com/) and first submitting transactions directly to the Hedera
|
58
|
+
network without requiring interaction with a [Wallet](#hedera-wallets) when integrating Hedera
|
59
|
+
for the first time. We also recommend reviewing the
|
60
|
+
[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
|
34
117
|
|
35
118
|
1. Follow one of the quickstart instructions at
|
36
119
|
https://docs.reown.com/appkit/overview#quickstart
|
@@ -122,8 +205,34 @@ createAppKit({
|
|
122
205
|
})
|
123
206
|
```
|
124
207
|
|
125
|
-
|
208
|
+
### Examples, demos, and tools
|
126
209
|
|
127
|
-
- [
|
128
|
-
- [
|
129
|
-
- [
|
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 a node id or
|
237
|
+
set of node id's set to be able to serialize into bytes to be passed sent over a network and
|
238
|
+
deserialized by the SDK.
|