@appliedblockchain/silentdatarollup-viem 1.0.2
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 +121 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +55 -0
- package/dist/index.mjs +30 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Silent Data [Rollup] Providers - Viem Transport Package
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Introduction](#introduction)
|
|
6
|
+
- [Prerequisites](#prerequisites)
|
|
7
|
+
- [Integration](#integration)
|
|
8
|
+
- [Basic Usage](#basic-usage)
|
|
9
|
+
- [Installing Basic Usage Dependencies](#installing-basic-usage-dependencies)
|
|
10
|
+
- [Basic Usage Example](#basic-usage-example)
|
|
11
|
+
- [Troubleshooting](#troubleshooting)
|
|
12
|
+
- [License](#license)
|
|
13
|
+
- [Additional Resources](#additional-resources)
|
|
14
|
+
|
|
15
|
+
## Introduction
|
|
16
|
+
|
|
17
|
+
Viem custom transport for Silent Data [Rollup].
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
- Node.js (version 18 or higher)
|
|
22
|
+
- npm
|
|
23
|
+
- Basic knowledge of Ethereum and smart contracts
|
|
24
|
+
- Viem
|
|
25
|
+
|
|
26
|
+
## Integration
|
|
27
|
+
|
|
28
|
+
### Basic Usage
|
|
29
|
+
|
|
30
|
+
#### Installing Basic Usage Dependencies
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @appliedblockchain/silentdatarollup-core @appliedblockchain/silentdatarollup-viem
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Basic Usage Example
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import {
|
|
40
|
+
type Chain,
|
|
41
|
+
defineChain,
|
|
42
|
+
createPublicClient,
|
|
43
|
+
createWalletClient,
|
|
44
|
+
formatEther,
|
|
45
|
+
type CallParameters,
|
|
46
|
+
publicActions,
|
|
47
|
+
} from 'viem'
|
|
48
|
+
import { transport } from '@appliedblockchain/silentdatarollup-viem'
|
|
49
|
+
|
|
50
|
+
// For transaction signing and sending, create an account from the private key
|
|
51
|
+
const account = privateKeyToAccount(providerConfig.privateKey as `0x${string}`)
|
|
52
|
+
const walletClient = createWalletClient({
|
|
53
|
+
chain: silentDataChain,
|
|
54
|
+
transport,
|
|
55
|
+
account,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const transport = sdTransport({
|
|
59
|
+
rpcUrl: 'SILENT_DATA_ROLLUP_RPC_URL',
|
|
60
|
+
chainId: SILENT_DATA_CHAIN_ID,
|
|
61
|
+
privateKey: 'YOUR_PRIVATE_KEY',
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const client = createPublicClient({
|
|
65
|
+
transport,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const balance = await publicClient.getBalance({ address })
|
|
69
|
+
console.log('Balance:', balance)
|
|
70
|
+
|
|
71
|
+
const transactionCount = await publicClient.getTransactionCount({ address })
|
|
72
|
+
console.log('Transaction count:', transactionCount)
|
|
73
|
+
|
|
74
|
+
const sdChain = defineChain({
|
|
75
|
+
id: SILENT_DATA_CHAIN_ID,
|
|
76
|
+
name: 'SILENT_DATA_CHAIN_NAME',
|
|
77
|
+
nativeCurrency: {
|
|
78
|
+
name: 'Ether',
|
|
79
|
+
symbol: 'ETH',
|
|
80
|
+
decimals: 18,
|
|
81
|
+
},
|
|
82
|
+
rpcUrls: {
|
|
83
|
+
default: {
|
|
84
|
+
http: ['SILENT_DATA_ROLLUP_RPC_URL'],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const walletClient = createWalletClient({
|
|
90
|
+
chain: silentDataChain,
|
|
91
|
+
transport,
|
|
92
|
+
account,
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
const recipientAddress = 'RECIPIENT_ADDRESS'
|
|
96
|
+
const amountInWei = BigInt('1')
|
|
97
|
+
|
|
98
|
+
const transactionHash = await walletClient.sendTransaction({
|
|
99
|
+
to: recipientAddress,
|
|
100
|
+
value: amountInWei,
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
console.log('Transaction Hash:', transactionHash)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
109
|
+
|
|
110
|
+
## Troubleshooting
|
|
111
|
+
|
|
112
|
+
If you encounter any issues, please check the following:
|
|
113
|
+
|
|
114
|
+
1. Ensure you're using the correct RPC URL for your desired network.
|
|
115
|
+
2. Verify that your private key is correctly set.
|
|
116
|
+
3. Ensure that your token is active on the SilentData AppChains dashboard.
|
|
117
|
+
|
|
118
|
+
## Additional Resources
|
|
119
|
+
|
|
120
|
+
- [Silent Data [Rollup] Documentation](https://docs.silentdata.com)
|
|
121
|
+
- [Viem Documentation](https://viem.sh/docs/)
|
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
sdTransport: () => sdTransport
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/transport.ts
|
|
28
|
+
var import_silentdatarollup_ethers_provider = require("@appliedblockchain/silentdatarollup-ethers-provider");
|
|
29
|
+
var import_viem = require("viem");
|
|
30
|
+
var sdTransport = (config) => {
|
|
31
|
+
const providerConfig = config;
|
|
32
|
+
const ethersProvider = new import_silentdatarollup_ethers_provider.SilentDataRollupProvider(providerConfig);
|
|
33
|
+
const transport = (0, import_viem.custom)({
|
|
34
|
+
request: async ({ method, params }) => {
|
|
35
|
+
const txData = params?.[0] ?? {};
|
|
36
|
+
if (method === "eth_sendTransaction" && ethersProvider.signer && !txData.nonce) {
|
|
37
|
+
const signerAddress = await ethersProvider.signer.getAddress();
|
|
38
|
+
const nonce = await ethersProvider.getTransactionCount(
|
|
39
|
+
signerAddress,
|
|
40
|
+
"latest"
|
|
41
|
+
);
|
|
42
|
+
txData.nonce = nonce;
|
|
43
|
+
}
|
|
44
|
+
if (method === "eth_getBlockByNumber" && Array.isArray(params) && params.length > 1) {
|
|
45
|
+
params[1] = false;
|
|
46
|
+
}
|
|
47
|
+
return await ethersProvider.send(method, params || []);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return transport;
|
|
51
|
+
};
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
sdTransport
|
|
55
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/transport.ts
|
|
2
|
+
import {
|
|
3
|
+
SilentDataRollupProvider
|
|
4
|
+
} from "@appliedblockchain/silentdatarollup-ethers-provider";
|
|
5
|
+
import { custom } from "viem";
|
|
6
|
+
var sdTransport = (config) => {
|
|
7
|
+
const providerConfig = config;
|
|
8
|
+
const ethersProvider = new SilentDataRollupProvider(providerConfig);
|
|
9
|
+
const transport = custom({
|
|
10
|
+
request: async ({ method, params }) => {
|
|
11
|
+
const txData = params?.[0] ?? {};
|
|
12
|
+
if (method === "eth_sendTransaction" && ethersProvider.signer && !txData.nonce) {
|
|
13
|
+
const signerAddress = await ethersProvider.signer.getAddress();
|
|
14
|
+
const nonce = await ethersProvider.getTransactionCount(
|
|
15
|
+
signerAddress,
|
|
16
|
+
"latest"
|
|
17
|
+
);
|
|
18
|
+
txData.nonce = nonce;
|
|
19
|
+
}
|
|
20
|
+
if (method === "eth_getBlockByNumber" && Array.isArray(params) && params.length > 1) {
|
|
21
|
+
params[1] = false;
|
|
22
|
+
}
|
|
23
|
+
return await ethersProvider.send(method, params || []);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return transport;
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
sdTransport
|
|
30
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@appliedblockchain/silentdatarollup-viem",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Viem package for Silent Data [Rollup]",
|
|
5
|
+
"author": "Applied Blockchain",
|
|
6
|
+
"homepage": "https://github.com/appliedblockchain/silent-data-rollup-providers#readme",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"ethereum",
|
|
9
|
+
"provider",
|
|
10
|
+
"silentdata",
|
|
11
|
+
"rollup",
|
|
12
|
+
"ethers",
|
|
13
|
+
"viem"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": "https://github.com/appliedblockchain/silent-data-rollup-providers",
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.mjs",
|
|
23
|
+
"require": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
31
|
+
"check-exports": "attw --pack . --profile node16",
|
|
32
|
+
"prepack": "npm run build",
|
|
33
|
+
"test": "jest"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@appliedblockchain/silentdatarollup-core": "1.0.2",
|
|
37
|
+
"@appliedblockchain/silentdatarollup-ethers-provider": "1.0.2",
|
|
38
|
+
"viem": "2.31.4"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "22.5.4",
|
|
42
|
+
"ts-node": "10.9.2",
|
|
43
|
+
"typescript": "5.6.2"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|