@settlemint/sdk-viem 2.1.4-prb82292ad → 2.1.4-prb988c058
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 +63 -11
- 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:59](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L59)
|
|
53
53
|
|
|
54
54
|
Get a public client. Use this if you need to read from the blockchain.
|
|
55
55
|
|
|
@@ -65,16 +65,39 @@ 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
|
+
|
|
68
85
|
***
|
|
69
86
|
|
|
70
87
|
#### getWalletClient()
|
|
71
88
|
|
|
72
|
-
> **getWalletClient
|
|
89
|
+
> **getWalletClient**\<`C`\>(`options`): (`verificationOptions?`) => `object`
|
|
73
90
|
|
|
74
|
-
Defined in: [sdk/viem/src/viem.ts:
|
|
91
|
+
Defined in: [sdk/viem/src/viem.ts:121](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L121)
|
|
75
92
|
|
|
76
93
|
Get a wallet client. Use this if you need to write to the blockchain.
|
|
77
94
|
|
|
95
|
+
##### Type Parameters
|
|
96
|
+
|
|
97
|
+
| Type Parameter |
|
|
98
|
+
| ------ |
|
|
99
|
+
| `C` *extends* `Chain` |
|
|
100
|
+
|
|
78
101
|
##### Parameters
|
|
79
102
|
|
|
80
103
|
| Parameter | Type | Description |
|
|
@@ -97,11 +120,39 @@ A function that returns a wallet client. The function can be called with verific
|
|
|
97
120
|
|
|
98
121
|
`object`
|
|
99
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
|
+
|
|
100
151
|
### Interfaces
|
|
101
152
|
|
|
102
153
|
#### ClientOptions
|
|
103
154
|
|
|
104
|
-
Defined in: [sdk/viem/src/viem.ts:
|
|
155
|
+
Defined in: [sdk/viem/src/viem.ts:16](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L16)
|
|
105
156
|
|
|
106
157
|
The options for the viem client.
|
|
107
158
|
|
|
@@ -109,16 +160,17 @@ The options for the viem client.
|
|
|
109
160
|
|
|
110
161
|
| Property | Type | Description | Defined in |
|
|
111
162
|
| ------ | ------ | ------ | ------ |
|
|
112
|
-
| <a id="
|
|
113
|
-
| <a id="
|
|
114
|
-
| <a id="
|
|
115
|
-
| <a id="
|
|
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) |
|
|
116
168
|
|
|
117
169
|
***
|
|
118
170
|
|
|
119
171
|
#### WalletVerificationOptions
|
|
120
172
|
|
|
121
|
-
Defined in: [sdk/viem/src/viem.ts:
|
|
173
|
+
Defined in: [sdk/viem/src/viem.ts:79](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/viem/src/viem.ts#L79)
|
|
122
174
|
|
|
123
175
|
The options for the wallet client.
|
|
124
176
|
|
|
@@ -126,8 +178,8 @@ The options for the wallet client.
|
|
|
126
178
|
|
|
127
179
|
| Property | Type | Description | Defined in |
|
|
128
180
|
| ------ | ------ | ------ | ------ |
|
|
129
|
-
| <a id="challengeresponse"></a> `challengeResponse` | `string` | The challenge response (used for HD wallets) | [sdk/viem/src/viem.ts:
|
|
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:
|
|
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) |
|
|
131
183
|
|
|
132
184
|
## Contributing
|
|
133
185
|
|
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: 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"]}
|
|
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"]}
|
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: 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!,
|
|
39
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
|
|
40
|
+
* chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
41
|
+
* chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
42
|
+
* rpcUrl: process.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: 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!,
|
|
6960
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
|
|
6961
|
+
* chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
6962
|
+
* chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
6963
|
+
* rpcUrl: process.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: 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!,
|
|
39
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
|
|
40
|
+
* chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
41
|
+
* chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
42
|
+
* rpcUrl: process.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: 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!,
|
|
6960
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
|
|
6961
|
+
* chainId: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK_CHAIN_ID!,
|
|
6962
|
+
* chainName: process.env.SETTLEMINT_BLOCKCHAIN_NETWORK!,
|
|
6963
|
+
* rpcUrl: process.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: 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"]}
|
|
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":"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-prb988c058",
|
|
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-prb988c058",
|
|
55
55
|
"viem": "^2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {},
|