@settlemint/sdk-viem 2.1.4-main0ca0d06f
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/LICENSE +110 -0
- package/README.md +190 -0
- package/dist/viem.cjs +2 -0
- package/dist/viem.cjs.map +1 -0
- package/dist/viem.d.cts +6983 -0
- package/dist/viem.d.ts +6983 -0
- package/dist/viem.mjs +2 -0
- package/dist/viem.mjs.map +1 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2024 SettleMint
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://github.com/settlemint/sdk/blob/main/logo.svg" width="200px" align="center" alt="SettleMint logo" />
|
|
3
|
+
<h1 align="center">SettleMint SDK</h1>
|
|
4
|
+
<p align="center">
|
|
5
|
+
✨ <a href="https://settlemint.com">https://settlemint.com</a> ✨
|
|
6
|
+
<br/>
|
|
7
|
+
Integrate SettleMint into your application with ease.
|
|
8
|
+
</p>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://github.com/settlemint/sdk/actions?query=branch%3Amain"><img src="https://github.com/settlemint/sdk/actions/workflows/build.yml/badge.svg?event=push&branch=main" alt="CI status" /></a>
|
|
13
|
+
<a href="https://fsl.software" rel="nofollow"><img src="https://img.shields.io/npm/l/@settlemint/sdk-viem" alt="License"></a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/@settlemint/sdk-viem" rel="nofollow"><img src="https://img.shields.io/npm/dw/@settlemint/sdk-viem" alt="npm"></a>
|
|
15
|
+
<a href="https://github.com/settlemint/sdk" rel="nofollow"><img src="https://img.shields.io/github/stars/settlemint/sdk" alt="stars"></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<div align="center">
|
|
19
|
+
<a href="https://console.settlemint.com/documentation">Documentation</a>
|
|
20
|
+
<span> • </span>
|
|
21
|
+
<a href="https://www.npmjs.com/package/@settlemint/sdk-viem">NPM</a>
|
|
22
|
+
<span> • </span>
|
|
23
|
+
<a href="https://github.com/settlemint/sdk/issues">Issues</a>
|
|
24
|
+
<br />
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
## Table of Contents
|
|
28
|
+
|
|
29
|
+
- [About](#about)
|
|
30
|
+
- [API Reference](#api-reference)
|
|
31
|
+
- [Functions](#functions)
|
|
32
|
+
- [getPublicClient()](#getpublicclient)
|
|
33
|
+
- [getWalletClient()](#getwalletclient)
|
|
34
|
+
- [Interfaces](#interfaces)
|
|
35
|
+
- [ClientOptions](#clientoptions)
|
|
36
|
+
- [WalletVerificationOptions](#walletverificationoptions)
|
|
37
|
+
- [Contributing](#contributing)
|
|
38
|
+
- [License](#license)
|
|
39
|
+
|
|
40
|
+
## About
|
|
41
|
+
|
|
42
|
+
The SettleMint Viem SDK provides a lightweight wrapper that automatically configures and sets up a Viem client based on your connected SettleMint application. It simplifies the process of establishing connections to SettleMint-managed blockchain networks by handling authentication, endpoint configuration, and chain selection. This allows developers to quickly start using Viem's powerful Ethereum interaction capabilities without manual setup, while ensuring proper integration with the SettleMint platform.
|
|
43
|
+
|
|
44
|
+
## API Reference
|
|
45
|
+
|
|
46
|
+
### Functions
|
|
47
|
+
|
|
48
|
+
#### getPublicClient()
|
|
49
|
+
|
|
50
|
+
> **getPublicClient**(`options`): `object`
|
|
51
|
+
|
|
52
|
+
Defined in: [sdk/viem/src/viem.ts:59](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L59)
|
|
53
|
+
|
|
54
|
+
Get a public client. Use this if you need to read from the blockchain.
|
|
55
|
+
|
|
56
|
+
##### Parameters
|
|
57
|
+
|
|
58
|
+
| Parameter | Type | Description |
|
|
59
|
+
| ------ | ------ | ------ |
|
|
60
|
+
| `options` | [`ClientOptions`](#clientoptions) | The options for the public client. |
|
|
61
|
+
|
|
62
|
+
##### Returns
|
|
63
|
+
|
|
64
|
+
`object`
|
|
65
|
+
|
|
66
|
+
The public client.
|
|
67
|
+
|
|
68
|
+
##### Example
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { getPublicClient } from '@settlemint/sdk-viem';
|
|
72
|
+
|
|
73
|
+
const publicClient = getPublicClient({
|
|
74
|
+
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
|
|
75
|
+
chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
76
|
+
chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
77
|
+
rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Get the block number
|
|
81
|
+
const block = await publicClient.getBlockNumber();
|
|
82
|
+
console.log(block);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
***
|
|
86
|
+
|
|
87
|
+
#### getWalletClient()
|
|
88
|
+
|
|
89
|
+
> **getWalletClient**\<`C`\>(`options`): (`verificationOptions?`) => `object`
|
|
90
|
+
|
|
91
|
+
Defined in: [sdk/viem/src/viem.ts:121](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L121)
|
|
92
|
+
|
|
93
|
+
Get a wallet client. Use this if you need to write to the blockchain.
|
|
94
|
+
|
|
95
|
+
##### Type Parameters
|
|
96
|
+
|
|
97
|
+
| Type Parameter |
|
|
98
|
+
| ------ |
|
|
99
|
+
| `C` *extends* `Chain` |
|
|
100
|
+
|
|
101
|
+
##### Parameters
|
|
102
|
+
|
|
103
|
+
| Parameter | Type | Description |
|
|
104
|
+
| ------ | ------ | ------ |
|
|
105
|
+
| `options` | [`ClientOptions`](#clientoptions) | The options for the wallet client. |
|
|
106
|
+
|
|
107
|
+
##### Returns
|
|
108
|
+
|
|
109
|
+
A function that returns a wallet client. The function can be called with verification options.
|
|
110
|
+
|
|
111
|
+
> (`verificationOptions?`): `object`
|
|
112
|
+
|
|
113
|
+
###### Parameters
|
|
114
|
+
|
|
115
|
+
| Parameter | Type |
|
|
116
|
+
| ------ | ------ |
|
|
117
|
+
| `verificationOptions?` | [`WalletVerificationOptions`](#walletverificationoptions) |
|
|
118
|
+
|
|
119
|
+
###### Returns
|
|
120
|
+
|
|
121
|
+
`object`
|
|
122
|
+
|
|
123
|
+
##### Example
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { getWalletClient } from '@settlemint/sdk-viem';
|
|
127
|
+
import { parseAbi } from "viem";
|
|
128
|
+
|
|
129
|
+
const walletClient = getWalletClient({
|
|
130
|
+
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
|
|
131
|
+
chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
132
|
+
chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
133
|
+
rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Get the chain id
|
|
137
|
+
const chainId = await walletClient().getChainId();
|
|
138
|
+
console.log(chainId);
|
|
139
|
+
|
|
140
|
+
// write to the blockchain
|
|
141
|
+
const transactionHash = await walletClient().writeContract({
|
|
142
|
+
account: "0x0000000000000000000000000000000000000000",
|
|
143
|
+
address: "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2",
|
|
144
|
+
abi: parseAbi(["function mint(uint32 tokenId) nonpayable"]),
|
|
145
|
+
functionName: "mint",
|
|
146
|
+
args: [69420],
|
|
147
|
+
});
|
|
148
|
+
console.log(transactionHash);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Interfaces
|
|
152
|
+
|
|
153
|
+
#### ClientOptions
|
|
154
|
+
|
|
155
|
+
Defined in: [sdk/viem/src/viem.ts:16](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L16)
|
|
156
|
+
|
|
157
|
+
The options for the viem client.
|
|
158
|
+
|
|
159
|
+
##### Properties
|
|
160
|
+
|
|
161
|
+
| Property | Type | Description | Defined in |
|
|
162
|
+
| ------ | ------ | ------ | ------ |
|
|
163
|
+
| <a id="accesstoken"></a> `accessToken` | `string` | The access token | [sdk/viem/src/viem.ts:20](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L20) |
|
|
164
|
+
| <a id="chainid"></a> `chainId` | `string` | The chain id | [sdk/viem/src/viem.ts:24](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L24) |
|
|
165
|
+
| <a id="chainname"></a> `chainName` | `string` | The chain name | [sdk/viem/src/viem.ts:28](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L28) |
|
|
166
|
+
| <a id="httptransportconfig"></a> `httpTransportConfig?` | `HttpTransportConfig` | The http transport config | [sdk/viem/src/viem.ts:36](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L36) |
|
|
167
|
+
| <a id="rpcurl"></a> `rpcUrl` | `string` | The json rpc url | [sdk/viem/src/viem.ts:32](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L32) |
|
|
168
|
+
|
|
169
|
+
***
|
|
170
|
+
|
|
171
|
+
#### WalletVerificationOptions
|
|
172
|
+
|
|
173
|
+
Defined in: [sdk/viem/src/viem.ts:79](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L79)
|
|
174
|
+
|
|
175
|
+
The options for the wallet client.
|
|
176
|
+
|
|
177
|
+
##### Properties
|
|
178
|
+
|
|
179
|
+
| Property | Type | Description | Defined in |
|
|
180
|
+
| ------ | ------ | ------ | ------ |
|
|
181
|
+
| <a id="challengeresponse"></a> `challengeResponse` | `string` | The challenge response (used for HD wallets) | [sdk/viem/src/viem.ts:87](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L87) |
|
|
182
|
+
| <a id="verificationid"></a> `verificationId?` | `string` | The verification id (used for HD wallets), if not provided, the challenge response will be validated against all active verifications. | [sdk/viem/src/viem.ts:83](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L83) |
|
|
183
|
+
|
|
184
|
+
## Contributing
|
|
185
|
+
|
|
186
|
+
We welcome contributions from the community! Please check out our [Contributing](https://github.com/settlemint/sdk/blob/main/.github/CONTRIBUTING.md) guide to learn how you can help improve the SettleMint SDK through bug reports, feature requests, documentation updates, or code contributions.
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
The SettleMint SDK is released under the [FSL Software License](https://fsl.software). See the [LICENSE](https://github.com/settlemint/sdk/blob/main/LICENSE) file for more details.
|
package/dist/viem.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var h=Object.create;var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var g=(t,e)=>{for(var n in e)a(t,n,{get:e[n],enumerable:!0})},c=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of l(e))!f.call(t,r)&&r!==n&&a(t,r,{get:()=>e[r],enumerable:!(s=p(e,r))||s.enumerable});return t};var m=(t,e,n)=>(n=t!=null?h(C(t)):{},c(e||!t||!t.__esModule?a(n,"default",{value:t,enumerable:!0}):n,t)),u=t=>c(a({},"__esModule",{value:!0}),t);var x={};g(x,{getPublicClient:()=>d,getWalletClient:()=>O});module.exports=u(x);var i=require("viem"),T=m(require("viem/chains"),1),d=t=>(0,i.createPublicClient)({chain:o(t),transport:(0,i.http)(t.rpcUrl,{batch:!0,timeout:6e4,...t.httpTransportConfig,fetchOptions:{...t?.httpTransportConfig?.fetchOptions,headers:{...t?.httpTransportConfig?.fetchOptions?.headers,"x-auth-token":t.accessToken}}})}),O=t=>{let e=o(t);return n=>(0,i.createWalletClient)({chain:e,transport:(0,i.http)(t.rpcUrl,{batch:!0,timeout:6e4,...t.httpTransportConfig,fetchOptions:{...t?.httpTransportConfig?.fetchOptions,headers:{...t?.httpTransportConfig?.fetchOptions?.headers,"x-auth-token":t.accessToken,"x-auth-challenge-response":n?.challengeResponse??"","x-auth-verification-id":n?.verificationId??""}}})})};function o({chainId:t,chainName:e,rpcUrl:n}){return Object.values(T).find(r=>r.id.toString()===t)??(0,i.defineChain)({id:Number(t),name:e,rpcUrls:{default:{http:[n]}},nativeCurrency:{decimals:18,name:"Ether",symbol:"ETH"}})}0&&(module.exports={getPublicClient,getWalletClient});
|
|
2
|
+
//# sourceMappingURL=viem.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/viem.ts"],"sourcesContent":["import {\n http,\n type HttpTransportConfig,\n type Chain as ViemChain,\n type Transport as ViemTransport,\n type WalletClient,\n createPublicClient,\n createWalletClient,\n defineChain,\n} from \"viem\";\nimport * as chains from \"viem/chains\";\n\n/**\n * The options for the viem client.\n */\nexport interface ClientOptions {\n /**\n * The access token\n */\n accessToken: string;\n /**\n * The chain id\n */\n chainId: string;\n /**\n * The chain name\n */\n chainName: string;\n /**\n * The json rpc url\n */\n rpcUrl: string;\n /**\n * The http transport config\n */\n httpTransportConfig?: HttpTransportConfig;\n}\n\n/**\n * Get a public client. Use this if you need to read from the blockchain.\n * @param options - The options for the public client.\n * @returns The public client.\n * @example\n * ```ts\n * import { getPublicClient } from '@settlemint/sdk-viem';\n *\n * const publicClient = getPublicClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the block number\n * const block = await publicClient.getBlockNumber();\n * console.log(block);\n * ```\n */\nexport const getPublicClient = (options: ClientOptions) =>\n createPublicClient({\n chain: getChain(options),\n transport: http(options.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...options.httpTransportConfig,\n fetchOptions: {\n ...options?.httpTransportConfig?.fetchOptions,\n headers: {\n ...options?.httpTransportConfig?.fetchOptions?.headers,\n \"x-auth-token\": options.accessToken,\n },\n },\n }),\n });\n\n/**\n * The options for the wallet client.\n */\nexport interface WalletVerificationOptions {\n /**\n * The verification id (used for HD wallets), if not provided, the challenge response will be validated against all active verifications.\n */\n verificationId?: string;\n /**\n * The challenge response (used for HD wallets)\n */\n challengeResponse: string;\n}\n\n/**\n * Get a wallet client. Use this if you need to write to the blockchain.\n * @param options - The options for the wallet client.\n * @returns A function that returns a wallet client. The function can be called with verification options.\n * @example\n * ```ts\n * import { getWalletClient } from '@settlemint/sdk-viem';\n * import { parseAbi } from \"viem\";\n *\n * const walletClient = getWalletClient({\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,\n * chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: process.env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,\n * });\n *\n * // Get the chain id\n * const chainId = await walletClient().getChainId();\n * console.log(chainId);\n *\n * // write to the blockchain\n * const transactionHash = await walletClient().writeContract({\n * account: \"0x0000000000000000000000000000000000000000\",\n * address: \"0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2\",\n * abi: parseAbi([\"function mint(uint32 tokenId) nonpayable\"]),\n * functionName: \"mint\",\n * args: [69420],\n * });\n * console.log(transactionHash);\n * ```\n */\nexport const getWalletClient = <C extends ViemChain>(options: ClientOptions) => {\n const chain = getChain(options);\n return (verificationOptions?: WalletVerificationOptions): WalletClient<ViemTransport, C> =>\n createWalletClient({\n chain: chain as ViemChain,\n transport: http(options.rpcUrl, {\n batch: true,\n timeout: 60_000,\n ...options.httpTransportConfig,\n fetchOptions: {\n ...options?.httpTransportConfig?.fetchOptions,\n headers: {\n ...options?.httpTransportConfig?.fetchOptions?.headers,\n \"x-auth-token\": options.accessToken,\n \"x-auth-challenge-response\": verificationOptions?.challengeResponse ?? \"\",\n \"x-auth-verification-id\": verificationOptions?.verificationId ?? \"\",\n },\n },\n }),\n }) as WalletClient<ViemTransport, C>;\n};\n\nfunction getChain({ chainId, chainName, rpcUrl }: Pick<ClientOptions, \"chainId\" | \"chainName\" | \"rpcUrl\">): ViemChain {\n const knownChain = Object.values(chains).find((chain) => chain.id.toString() === chainId);\n return (\n knownChain ??\n defineChain({\n id: Number(chainId),\n name: chainName,\n rpcUrls: {\n default: {\n http: [rpcUrl],\n },\n },\n nativeCurrency: {\n decimals: 18,\n name: \"Ether\",\n symbol: \"ETH\",\n },\n })\n );\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,oBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EASO,gBACPC,EAAwB,4BAgDXC,EAAmBC,MAC9B,sBAAmB,CACjB,MAAOC,EAASD,CAAO,EACvB,aAAW,QAAKA,EAAQ,OAAQ,CAC9B,MAAO,GACP,QAAS,IACT,GAAGA,EAAQ,oBACX,aAAc,CACZ,GAAGA,GAAS,qBAAqB,aACjC,QAAS,CACP,GAAGA,GAAS,qBAAqB,cAAc,QAC/C,eAAgBA,EAAQ,WAC1B,CACF,CACF,CAAC,CACH,CAAC,EA+CUE,EAAwCF,GAA2B,CAC9E,IAAMG,EAAQF,EAASD,CAAO,EAC9B,OAAQI,MACN,sBAAmB,CACjB,MAAOD,EACP,aAAW,QAAKH,EAAQ,OAAQ,CAC9B,MAAO,GACP,QAAS,IACT,GAAGA,EAAQ,oBACX,aAAc,CACZ,GAAGA,GAAS,qBAAqB,aACjC,QAAS,CACP,GAAGA,GAAS,qBAAqB,cAAc,QAC/C,eAAgBA,EAAQ,YACxB,4BAA6BI,GAAqB,mBAAqB,GACvE,yBAA0BA,GAAqB,gBAAkB,EACnE,CACF,CACF,CAAC,CACH,CAAC,CACL,EAEA,SAASH,EAAS,CAAE,QAAAI,EAAS,UAAAC,EAAW,OAAAC,CAAO,EAAuE,CAEpH,OADmB,OAAO,OAAOT,CAAM,EAAE,KAAMK,GAAUA,EAAM,GAAG,SAAS,IAAME,CAAO,MAGtF,eAAY,CACV,GAAI,OAAOA,CAAO,EAClB,KAAMC,EACN,QAAS,CACP,QAAS,CACP,KAAM,CAACC,CAAM,CACf,CACF,EACA,eAAgB,CACd,SAAU,GACV,KAAM,QACN,OAAQ,KACV,CACF,CAAC,CAEL","names":["viem_exports","__export","getPublicClient","getWalletClient","__toCommonJS","import_viem","chains","getPublicClient","options","getChain","getWalletClient","chain","verificationOptions","chainId","chainName","rpcUrl"]}
|