@settlemint/sdk-viem 2.1.4-prcae01a18 → 2.1.4-prcda675ba
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 +1 -1
- package/dist/viem.cjs.map +1 -1
- package/dist/viem.d.cts +52 -7
- package/dist/viem.d.ts +52 -7
- package/dist/viem.mjs +1 -1
- 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
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
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
2
|
//# sourceMappingURL=viem.cjs.map
|
package/dist/viem.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/viem.ts"],"sourcesContent":["import {\n http,\n type Chain,\n type
|
|
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
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
|
-
import { HttpTransportConfig, Chain, WalletClient } from 'viem';
|
|
3
|
-
import chains from 'viem/chains';
|
|
2
|
+
import { HttpTransportConfig, Chain, WalletClient, Transport } from 'viem';
|
|
3
|
+
import * as chains from 'viem/chains';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The options for the viem client.
|
|
7
7
|
*/
|
|
8
8
|
interface ClientOptions {
|
|
9
9
|
/**
|
|
10
|
-
* The
|
|
10
|
+
* The access token
|
|
11
|
+
*/
|
|
12
|
+
accessToken: string;
|
|
13
|
+
/**
|
|
14
|
+
* The chain id
|
|
11
15
|
*/
|
|
12
16
|
chainId: string;
|
|
13
17
|
/**
|
|
14
|
-
* The chain name
|
|
18
|
+
* The chain name
|
|
15
19
|
*/
|
|
16
20
|
chainName: string;
|
|
17
21
|
/**
|
|
18
|
-
* The rpc url
|
|
22
|
+
* The json rpc url
|
|
19
23
|
*/
|
|
20
24
|
rpcUrl: string;
|
|
21
25
|
/**
|
|
22
|
-
* The http transport config
|
|
26
|
+
* The http transport config
|
|
23
27
|
*/
|
|
24
28
|
httpTransportConfig?: HttpTransportConfig;
|
|
25
29
|
}
|
|
@@ -27,6 +31,21 @@ interface ClientOptions {
|
|
|
27
31
|
* Get a public client. Use this if you need to read from the blockchain.
|
|
28
32
|
* @param options - The options for the public client.
|
|
29
33
|
* @returns The public client.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { getPublicClient } from '@settlemint/sdk-viem';
|
|
37
|
+
*
|
|
38
|
+
* const publicClient = getPublicClient({
|
|
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
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Get the block number
|
|
46
|
+
* const block = await publicClient.getBlockNumber();
|
|
47
|
+
* console.log(block);
|
|
48
|
+
* ```
|
|
30
49
|
*/
|
|
31
50
|
declare const getPublicClient: (options: ClientOptions) => {
|
|
32
51
|
account: undefined;
|
|
@@ -6932,7 +6951,33 @@ interface WalletVerificationOptions {
|
|
|
6932
6951
|
* Get a wallet client. Use this if you need to write to the blockchain.
|
|
6933
6952
|
* @param options - The options for the wallet client.
|
|
6934
6953
|
* @returns A function that returns a wallet client. The function can be called with verification options.
|
|
6954
|
+
* @example
|
|
6955
|
+
* ```ts
|
|
6956
|
+
* import { getWalletClient } from '@settlemint/sdk-viem';
|
|
6957
|
+
* import { parseAbi } from "viem";
|
|
6958
|
+
*
|
|
6959
|
+
* const walletClient = getWalletClient({
|
|
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
|
+
* });
|
|
6965
|
+
*
|
|
6966
|
+
* // Get the chain id
|
|
6967
|
+
* const chainId = await walletClient().getChainId();
|
|
6968
|
+
* console.log(chainId);
|
|
6969
|
+
*
|
|
6970
|
+
* // write to the blockchain
|
|
6971
|
+
* const transactionHash = await walletClient().writeContract({
|
|
6972
|
+
* account: "0x0000000000000000000000000000000000000000",
|
|
6973
|
+
* address: "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2",
|
|
6974
|
+
* abi: parseAbi(["function mint(uint32 tokenId) nonpayable"]),
|
|
6975
|
+
* functionName: "mint",
|
|
6976
|
+
* args: [69420],
|
|
6977
|
+
* });
|
|
6978
|
+
* console.log(transactionHash);
|
|
6979
|
+
* ```
|
|
6935
6980
|
*/
|
|
6936
|
-
declare const getWalletClient: (options: ClientOptions) => (verificationOptions?: WalletVerificationOptions) => WalletClient
|
|
6981
|
+
declare const getWalletClient: <C extends Chain>(options: ClientOptions) => (verificationOptions?: WalletVerificationOptions) => WalletClient<Transport, C>;
|
|
6937
6982
|
|
|
6938
6983
|
export { type ClientOptions, type WalletVerificationOptions, getPublicClient, getWalletClient };
|
package/dist/viem.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
|
-
import { HttpTransportConfig, Chain, WalletClient } from 'viem';
|
|
3
|
-
import chains from 'viem/chains';
|
|
2
|
+
import { HttpTransportConfig, Chain, WalletClient, Transport } from 'viem';
|
|
3
|
+
import * as chains from 'viem/chains';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The options for the viem client.
|
|
7
7
|
*/
|
|
8
8
|
interface ClientOptions {
|
|
9
9
|
/**
|
|
10
|
-
* The
|
|
10
|
+
* The access token
|
|
11
|
+
*/
|
|
12
|
+
accessToken: string;
|
|
13
|
+
/**
|
|
14
|
+
* The chain id
|
|
11
15
|
*/
|
|
12
16
|
chainId: string;
|
|
13
17
|
/**
|
|
14
|
-
* The chain name
|
|
18
|
+
* The chain name
|
|
15
19
|
*/
|
|
16
20
|
chainName: string;
|
|
17
21
|
/**
|
|
18
|
-
* The rpc url
|
|
22
|
+
* The json rpc url
|
|
19
23
|
*/
|
|
20
24
|
rpcUrl: string;
|
|
21
25
|
/**
|
|
22
|
-
* The http transport config
|
|
26
|
+
* The http transport config
|
|
23
27
|
*/
|
|
24
28
|
httpTransportConfig?: HttpTransportConfig;
|
|
25
29
|
}
|
|
@@ -27,6 +31,21 @@ interface ClientOptions {
|
|
|
27
31
|
* Get a public client. Use this if you need to read from the blockchain.
|
|
28
32
|
* @param options - The options for the public client.
|
|
29
33
|
* @returns The public client.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { getPublicClient } from '@settlemint/sdk-viem';
|
|
37
|
+
*
|
|
38
|
+
* const publicClient = getPublicClient({
|
|
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
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Get the block number
|
|
46
|
+
* const block = await publicClient.getBlockNumber();
|
|
47
|
+
* console.log(block);
|
|
48
|
+
* ```
|
|
30
49
|
*/
|
|
31
50
|
declare const getPublicClient: (options: ClientOptions) => {
|
|
32
51
|
account: undefined;
|
|
@@ -6932,7 +6951,33 @@ interface WalletVerificationOptions {
|
|
|
6932
6951
|
* Get a wallet client. Use this if you need to write to the blockchain.
|
|
6933
6952
|
* @param options - The options for the wallet client.
|
|
6934
6953
|
* @returns A function that returns a wallet client. The function can be called with verification options.
|
|
6954
|
+
* @example
|
|
6955
|
+
* ```ts
|
|
6956
|
+
* import { getWalletClient } from '@settlemint/sdk-viem';
|
|
6957
|
+
* import { parseAbi } from "viem";
|
|
6958
|
+
*
|
|
6959
|
+
* const walletClient = getWalletClient({
|
|
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
|
+
* });
|
|
6965
|
+
*
|
|
6966
|
+
* // Get the chain id
|
|
6967
|
+
* const chainId = await walletClient().getChainId();
|
|
6968
|
+
* console.log(chainId);
|
|
6969
|
+
*
|
|
6970
|
+
* // write to the blockchain
|
|
6971
|
+
* const transactionHash = await walletClient().writeContract({
|
|
6972
|
+
* account: "0x0000000000000000000000000000000000000000",
|
|
6973
|
+
* address: "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2",
|
|
6974
|
+
* abi: parseAbi(["function mint(uint32 tokenId) nonpayable"]),
|
|
6975
|
+
* functionName: "mint",
|
|
6976
|
+
* args: [69420],
|
|
6977
|
+
* });
|
|
6978
|
+
* console.log(transactionHash);
|
|
6979
|
+
* ```
|
|
6935
6980
|
*/
|
|
6936
|
-
declare const getWalletClient: (options: ClientOptions) => (verificationOptions?: WalletVerificationOptions) => WalletClient
|
|
6981
|
+
declare const getWalletClient: <C extends Chain>(options: ClientOptions) => (verificationOptions?: WalletVerificationOptions) => WalletClient<Transport, C>;
|
|
6937
6982
|
|
|
6938
6983
|
export { type ClientOptions, type WalletVerificationOptions, getPublicClient, getWalletClient };
|
package/dist/viem.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{http as i,createPublicClient as
|
|
1
|
+
import{http as i,createPublicClient as s,createWalletClient as c,defineChain as o}from"viem";import*as h from"viem/chains";var g=t=>s({chain:r(t),transport:i(t.rpcUrl,{batch:!0,timeout:6e4,...t.httpTransportConfig,fetchOptions:{...t?.httpTransportConfig?.fetchOptions,headers:{...t?.httpTransportConfig?.fetchOptions?.headers,"x-auth-token":t.accessToken}}})}),m=t=>{let n=r(t);return e=>c({chain:n,transport:i(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":e?.challengeResponse??"","x-auth-verification-id":e?.verificationId??""}}})})};function r({chainId:t,chainName:n,rpcUrl:e}){return Object.values(h).find(a=>a.id.toString()===t)??o({id:Number(t),name:n,rpcUrls:{default:{http:[e]}},nativeCurrency:{decimals:18,name:"Ether",symbol:"ETH"}})}export{g as getPublicClient,m as getWalletClient};
|
|
2
2
|
//# sourceMappingURL=viem.mjs.map
|
package/dist/viem.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/viem.ts"],"sourcesContent":["import {\n http,\n type Chain,\n type
|
|
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-prcda675ba",
|
|
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-prcda675ba",
|
|
55
55
|
"viem": "^2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {},
|