@settlemint/sdk-viem 2.1.4-pr8cee5361 → 2.1.4-prb82292ad
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 +11 -63
- package/dist/viem.cjs.map +1 -1
- package/dist/viem.d.cts +8 -8
- package/dist/viem.d.ts +8 -8
- package/dist/viem.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ The SettleMint Viem SDK provides a lightweight wrapper that automatically config
|
|
|
49
49
|
|
|
50
50
|
> **getPublicClient**(`options`): `object`
|
|
51
51
|
|
|
52
|
-
Defined in: [sdk/viem/src/viem.ts:
|
|
52
|
+
Defined in: [sdk/viem/src/viem.ts:39](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L39)
|
|
53
53
|
|
|
54
54
|
Get a public client. Use this if you need to read from the blockchain.
|
|
55
55
|
|
|
@@ -65,39 +65,16 @@ Get a public client. Use this if you need to read from the blockchain.
|
|
|
65
65
|
|
|
66
66
|
The public client.
|
|
67
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
68
|
***
|
|
86
69
|
|
|
87
70
|
#### getWalletClient()
|
|
88
71
|
|
|
89
|
-
> **getWalletClient
|
|
72
|
+
> **getWalletClient**(`options`): (`verificationOptions?`) => `object`
|
|
90
73
|
|
|
91
|
-
Defined in: [sdk/viem/src/viem.ts:
|
|
74
|
+
Defined in: [sdk/viem/src/viem.ts:68](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L68)
|
|
92
75
|
|
|
93
76
|
Get a wallet client. Use this if you need to write to the blockchain.
|
|
94
77
|
|
|
95
|
-
##### Type Parameters
|
|
96
|
-
|
|
97
|
-
| Type Parameter |
|
|
98
|
-
| ------ |
|
|
99
|
-
| `C` *extends* `Chain` |
|
|
100
|
-
|
|
101
78
|
##### Parameters
|
|
102
79
|
|
|
103
80
|
| Parameter | Type | Description |
|
|
@@ -120,39 +97,11 @@ A function that returns a wallet client. The function can be called with verific
|
|
|
120
97
|
|
|
121
98
|
`object`
|
|
122
99
|
|
|
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
100
|
### Interfaces
|
|
152
101
|
|
|
153
102
|
#### ClientOptions
|
|
154
103
|
|
|
155
|
-
Defined in: [sdk/viem/src/viem.ts:
|
|
104
|
+
Defined in: [sdk/viem/src/viem.ts:15](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L15)
|
|
156
105
|
|
|
157
106
|
The options for the viem client.
|
|
158
107
|
|
|
@@ -160,17 +109,16 @@ The options for the viem client.
|
|
|
160
109
|
|
|
161
110
|
| Property | Type | Description | Defined in |
|
|
162
111
|
| ------ | ------ | ------ | ------ |
|
|
163
|
-
| <a id="
|
|
164
|
-
| <a id="
|
|
165
|
-
| <a id="
|
|
166
|
-
| <a id="
|
|
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) |
|
|
112
|
+
| <a id="chainid"></a> `chainId` | `string` | The chain id to use for the viem client. | [sdk/viem/src/viem.ts:19](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L19) |
|
|
113
|
+
| <a id="chainname"></a> `chainName` | `string` | The chain name to use for the viem client. | [sdk/viem/src/viem.ts:23](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L23) |
|
|
114
|
+
| <a id="httptransportconfig"></a> `httpTransportConfig?` | `HttpTransportConfig` | The http transport config to use for the wallet client. | [sdk/viem/src/viem.ts:31](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L31) |
|
|
115
|
+
| <a id="rpcurl"></a> `rpcUrl` | `string` | The rpc url to use for the viem client. | [sdk/viem/src/viem.ts:27](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L27) |
|
|
168
116
|
|
|
169
117
|
***
|
|
170
118
|
|
|
171
119
|
#### WalletVerificationOptions
|
|
172
120
|
|
|
173
|
-
Defined in: [sdk/viem/src/viem.ts:
|
|
121
|
+
Defined in: [sdk/viem/src/viem.ts:52](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L52)
|
|
174
122
|
|
|
175
123
|
The options for the wallet client.
|
|
176
124
|
|
|
@@ -178,8 +126,8 @@ The options for the wallet client.
|
|
|
178
126
|
|
|
179
127
|
| Property | Type | Description | Defined in |
|
|
180
128
|
| ------ | ------ | ------ | ------ |
|
|
181
|
-
| <a id="challengeresponse"></a> `challengeResponse` | `string` | The challenge response (used for HD wallets) | [sdk/viem/src/viem.ts:
|
|
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:
|
|
129
|
+
| <a id="challengeresponse"></a> `challengeResponse` | `string` | The challenge response (used for HD wallets) | [sdk/viem/src/viem.ts:60](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L60) |
|
|
130
|
+
| <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:56](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L56) |
|
|
183
131
|
|
|
184
132
|
## Contributing
|
|
185
133
|
|
package/dist/viem.cjs.map
CHANGED
|
@@ -1 +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:
|
|
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: env.SETTLEMINT_ACCESS_TOKEN!,\n * chainId: env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: 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: env.SETTLEMINT_ACCESS_TOKEN!,\n * chainId: env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: 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"]}
|
package/dist/viem.d.cts
CHANGED
|
@@ -36,10 +36,10 @@ interface ClientOptions {
|
|
|
36
36
|
* import { getPublicClient } from '@settlemint/sdk-viem';
|
|
37
37
|
*
|
|
38
38
|
* const publicClient = getPublicClient({
|
|
39
|
-
* accessToken:
|
|
40
|
-
* chainId:
|
|
41
|
-
* chainName:
|
|
42
|
-
* rpcUrl:
|
|
39
|
+
* accessToken: env.SETTLEMINT_ACCESS_TOKEN!,
|
|
40
|
+
* chainId: env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
41
|
+
* chainName: env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
42
|
+
* rpcUrl: env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,
|
|
43
43
|
* });
|
|
44
44
|
*
|
|
45
45
|
* // Get the block number
|
|
@@ -6957,10 +6957,10 @@ interface WalletVerificationOptions {
|
|
|
6957
6957
|
* import { parseAbi } from "viem";
|
|
6958
6958
|
*
|
|
6959
6959
|
* const walletClient = getWalletClient({
|
|
6960
|
-
* accessToken:
|
|
6961
|
-
* chainId:
|
|
6962
|
-
* chainName:
|
|
6963
|
-
* rpcUrl:
|
|
6960
|
+
* accessToken: env.SETTLEMINT_ACCESS_TOKEN!,
|
|
6961
|
+
* chainId: env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
6962
|
+
* chainName: env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
6963
|
+
* rpcUrl: env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,
|
|
6964
6964
|
* });
|
|
6965
6965
|
*
|
|
6966
6966
|
* // Get the chain id
|
package/dist/viem.d.ts
CHANGED
|
@@ -36,10 +36,10 @@ interface ClientOptions {
|
|
|
36
36
|
* import { getPublicClient } from '@settlemint/sdk-viem';
|
|
37
37
|
*
|
|
38
38
|
* const publicClient = getPublicClient({
|
|
39
|
-
* accessToken:
|
|
40
|
-
* chainId:
|
|
41
|
-
* chainName:
|
|
42
|
-
* rpcUrl:
|
|
39
|
+
* accessToken: env.SETTLEMINT_ACCESS_TOKEN!,
|
|
40
|
+
* chainId: env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
41
|
+
* chainName: env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
42
|
+
* rpcUrl: env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,
|
|
43
43
|
* });
|
|
44
44
|
*
|
|
45
45
|
* // Get the block number
|
|
@@ -6957,10 +6957,10 @@ interface WalletVerificationOptions {
|
|
|
6957
6957
|
* import { parseAbi } from "viem";
|
|
6958
6958
|
*
|
|
6959
6959
|
* const walletClient = getWalletClient({
|
|
6960
|
-
* accessToken:
|
|
6961
|
-
* chainId:
|
|
6962
|
-
* chainName:
|
|
6963
|
-
* rpcUrl:
|
|
6960
|
+
* accessToken: env.SETTLEMINT_ACCESS_TOKEN!,
|
|
6961
|
+
* chainId: env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
6962
|
+
* chainName: env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
6963
|
+
* rpcUrl: env.SETTLEMINT_BLOCKCHAIN_NODE_OR_LOAD_BALANCER_JSON_RPC_ENDPOINT!,
|
|
6964
6964
|
* });
|
|
6965
6965
|
*
|
|
6966
6966
|
* // Get the chain id
|
package/dist/viem.mjs.map
CHANGED
|
@@ -1 +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:
|
|
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: env.SETTLEMINT_ACCESS_TOKEN!,\n * chainId: env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: 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: env.SETTLEMINT_ACCESS_TOKEN!,\n * chainId: env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,\n * chainName: env.SETTLEMINT_BLOCKCHAIN_NETWORK!,\n * rpcUrl: 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":"AAAA,OACE,QAAAA,EAKA,sBAAAC,EACA,sBAAAC,EACA,eAAAC,MACK,OACP,UAAYC,MAAY,cAgDjB,IAAMC,EAAmBC,GAC9BL,EAAmB,CACjB,MAAOM,EAASD,CAAO,EACvB,UAAWN,EAAKM,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,GACNR,EAAmB,CACjB,MAAOO,EACP,UAAWT,EAAKM,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,GAGtFR,EAAY,CACV,GAAI,OAAOQ,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":["http","createPublicClient","createWalletClient","defineChain","chains","getPublicClient","options","getChain","getWalletClient","chain","verificationOptions","chainId","chainName","rpcUrl"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlemint/sdk-viem",
|
|
3
3
|
"description": "Viem (TypeScript Interface for Ethereum) module for SettleMint SDK",
|
|
4
|
-
"version": "2.1.4-
|
|
4
|
+
"version": "2.1.4-prb82292ad",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@settlemint/sdk-utils": "2.1.4-
|
|
54
|
+
"@settlemint/sdk-utils": "2.1.4-prb82292ad",
|
|
55
55
|
"viem": "^2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {},
|