@settlemint/sdk-viem 2.1.4-mainc63d4cc2

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/dist/viem.mjs ADDED
@@ -0,0 +1,2 @@
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
+ //# sourceMappingURL=viem.mjs.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":"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 ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@settlemint/sdk-viem",
3
+ "description": "Viem (TypeScript Interface for Ethereum) module for SettleMint SDK",
4
+ "version": "2.1.4-mainc63d4cc2",
5
+ "type": "module",
6
+ "private": false,
7
+ "license": "FSL-1.1-MIT",
8
+ "author": {
9
+ "name": "SettleMint",
10
+ "email": "support@settlemint.com",
11
+ "url": "https://settlemint.com"
12
+ },
13
+ "homepage": "https://github.com/settlemint/sdk/blob/main/sdk/viem/README.md",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/settlemint/sdk.git",
17
+ "directory": "sdk/viem"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/settlemint/sdk/issues",
21
+ "email": "support@settlemint.com"
22
+ },
23
+ "files": ["dist"],
24
+ "main": "./dist/viem.cjs",
25
+ "module": "./dist/viem.mjs",
26
+ "types": "./dist/viem.d.ts",
27
+ "exports": {
28
+ "./package.json": "./package.json",
29
+ ".": {
30
+ "import": {
31
+ "types": "./dist/viem.d.ts",
32
+ "default": "./dist/viem.mjs"
33
+ },
34
+ "require": {
35
+ "types": "./dist/viem.d.cts",
36
+ "default": "./dist/viem.cjs"
37
+ }
38
+ }
39
+ },
40
+ "scripts": {
41
+ "build": "tsup-node",
42
+ "dev": "tsup-node --watch",
43
+ "publint": "publint run --strict",
44
+ "attw": "attw --pack .",
45
+ "test": "bun test",
46
+ "test:coverage": "bun test --coverage",
47
+ "typecheck": "tsc --noEmit",
48
+ "publish-npm": "bun publish --tag ${TAG} --access public || exit 0",
49
+ "prepack": "cp ../../LICENSE .",
50
+ "docs": "typedoc --options '../../typedoc.config.mjs' --entryPoints src/viem.ts --out ./docs"
51
+ },
52
+ "devDependencies": {},
53
+ "dependencies": {
54
+ "@settlemint/sdk-utils": "2.1.4-mainc63d4cc2",
55
+ "viem": "^2"
56
+ },
57
+ "peerDependencies": {},
58
+ "engines": {
59
+ "node": ">=20"
60
+ },
61
+ "keywords": [
62
+ "settlemint",
63
+ "blockchain",
64
+ "blockchain-development",
65
+ "enterprise-blockchain",
66
+ "web3",
67
+ "web3-development",
68
+ "web3-tools",
69
+ "sdk",
70
+ "typescript",
71
+ "eth",
72
+ "ethereum",
73
+ "dapps",
74
+ "wallet"
75
+ ]
76
+ }