@appliedblockchain/silentdatarollup-ethers-provider-fireblocks 1.0.0
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 +119 -0
- package/dist/index.d.mts +65 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +45165 -0
- package/dist/index.mjs +45181 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Silent Data [Rollup] Providers - Ethers Provider Fireblocks Package
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Introduction](#introduction)
|
|
6
|
+
- [Prerequisites](#prerequisites)
|
|
7
|
+
- [Integration](#integration)
|
|
8
|
+
- [Fireblocks Integration](#fireblocks-integration)
|
|
9
|
+
- [Installing Fireblocks Integration Dependencies](#installing-fireblocks-integration-dependencies)
|
|
10
|
+
- [Fireblocks Integration Example](#fireblocks-integration-example)
|
|
11
|
+
- [Troubleshooting](#troubleshooting)
|
|
12
|
+
- [License](#license)
|
|
13
|
+
- [Additional Resources](#additional-resources)
|
|
14
|
+
|
|
15
|
+
## Introduction
|
|
16
|
+
|
|
17
|
+
Custom providers for Silent Data [Rollup], compatible with ethers.js for Fireblocks integration.
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
- Node.js (version 18 or higher)
|
|
22
|
+
- npm
|
|
23
|
+
- Basic knowledge of Ethereum and smart contracts
|
|
24
|
+
- Ethers.js v6
|
|
25
|
+
|
|
26
|
+
## Integration
|
|
27
|
+
|
|
28
|
+
### Fireblocks Integration
|
|
29
|
+
|
|
30
|
+
#### Installing Fireblocks Integration Dependencies
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @appliedblockchain/silentdatarollup-core @appliedblockchain/silentdatarollup-ethers-provider-fireblocks ethers@6 @fireblocks/fireblocks-web3-provider
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Fireblocks Integration Example
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import {
|
|
40
|
+
ApiBaseUrl,
|
|
41
|
+
ChainId,
|
|
42
|
+
FireblocksWeb3Provider,
|
|
43
|
+
} from '@fireblocks/fireblocks-web3-provider'
|
|
44
|
+
import {
|
|
45
|
+
BaseConfig,
|
|
46
|
+
SilentDataRollupContract,
|
|
47
|
+
} from '@appliedblockchain/silentdatarollup-core'
|
|
48
|
+
import { SilentDataRollupFireblocksProvider } from '@appliedblockchain/silentdatarollup-ethers-provider-fireblocks'
|
|
49
|
+
|
|
50
|
+
const RPC_URL = 'SILENT_DATA_ROLLUP_RPC_URL'
|
|
51
|
+
|
|
52
|
+
const eip1193Provider = new FireblocksWeb3Provider({
|
|
53
|
+
privateKey: 'FIREBLOCKS_PATH_TO_PRIVATE_KEY',
|
|
54
|
+
apiKey: 'FIREBLOCKS_API_KEY',
|
|
55
|
+
vaultAccountIds: 'FIREBLOCKS_VAULT_ACCOUNT_ID',
|
|
56
|
+
assetId: ASSETS[ChainId.SEPOLIA].assetId,
|
|
57
|
+
chainId: ChainId.SEPOLIA,
|
|
58
|
+
apiBaseUrl: ApiBaseUrl.Sandbox, // If using a sandbox workspace
|
|
59
|
+
rpcUrl: 'SILENT_DATA_ROLLUP_RPC_URL',
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const silentdataOptions: BaseConfig = {
|
|
63
|
+
authSignatureType: SignatureType.EIP712, // Optional, defaults to RAW
|
|
64
|
+
delegate: true, // Optional, defaults to false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const provider = new SilentDataRollupFireblocksProvider({
|
|
68
|
+
ethereum: eip1193Provider,
|
|
69
|
+
silentdataOptions,
|
|
70
|
+
})
|
|
71
|
+
const balance = await provider.getBalance('YOUR_ADDRESS')
|
|
72
|
+
console.log(balance)
|
|
73
|
+
|
|
74
|
+
const signer = await provider.getSigner()
|
|
75
|
+
const contractAddress = 'YOUR_CONTRACT_ADDRESS'
|
|
76
|
+
const abi = [
|
|
77
|
+
/* Your contract ABI */
|
|
78
|
+
]
|
|
79
|
+
const methodsToSign = ['balance'] // Contract read calls that require signing
|
|
80
|
+
|
|
81
|
+
const contract = new SilentDataRollupContract(
|
|
82
|
+
contractAddress,
|
|
83
|
+
abi,
|
|
84
|
+
signer,
|
|
85
|
+
methodsToSign,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
const tokenBalance = await contract.balance('YOUR_ADDRESS')
|
|
89
|
+
console.log(tokenBalance)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Note:** The SilentDataRollupFireblocksProvider adds an additional namespace on top of the Fireblocks provider for debugging purposes. This namespace is the same as the Fireblocks namespace with an additional `:silentdata-interceptor` suffix. For example, if the Fireblocks namespace is `fireblocks:web3-provider`, the SilentData provider's namespace would be `fireblocks:web3-provider:silentdata-interceptor`.
|
|
93
|
+
|
|
94
|
+
To enable debugging for the SilentData interceptor, you can set the following environment variable:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
DEBUG=fireblocks:web3-provider:silentdata-interceptor
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This will output debug information specific to the SilentData interceptor, helping you troubleshoot issues related to the Silent Data [Rollup] integration with Fireblocks.
|
|
101
|
+
|
|
102
|
+
## Troubleshooting
|
|
103
|
+
|
|
104
|
+
If you encounter any issues, please check the following:
|
|
105
|
+
|
|
106
|
+
1. Ensure you're using the correct RPC URL for your desired network.
|
|
107
|
+
2. Verify that the Fireblocks configuration is correctly set up and ensure your user and API keys are valid.
|
|
108
|
+
3. Ensure that your token is active on the SilentData AppChains dashboard.
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
113
|
+
|
|
114
|
+
## Additional Resources
|
|
115
|
+
|
|
116
|
+
- [Silent Data [Rollup] Documentation](https://docs.silentdata.com)
|
|
117
|
+
- [Ethers.js Documentation](https://docs.ethers.org/v6/)
|
|
118
|
+
- [Fireblocks Developer Documentation](https://developers.fireblocks.com/api)
|
|
119
|
+
- [Fireblocks Web3 Provider](https://developers.fireblocks.com/reference/evm-web3-provider)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BaseConfig } from '@appliedblockchain/silentdatarollup-core';
|
|
2
|
+
import { BrowserProvider, Eip1193Provider, Networkish, BrowserProviderOptions } from 'ethers';
|
|
3
|
+
|
|
4
|
+
declare const DEBUG_NAMESPACE_SILENTDATA_INTERCEPTOR = "fireblocks-web3-provider:silentdata-interceptor";
|
|
5
|
+
|
|
6
|
+
declare class SilentDataRollupFireblocksProvider extends BrowserProvider {
|
|
7
|
+
private lastNonce;
|
|
8
|
+
private ethereum;
|
|
9
|
+
private network;
|
|
10
|
+
private _options;
|
|
11
|
+
private config;
|
|
12
|
+
private baseProvider;
|
|
13
|
+
constructor({ ethereum, network, options, config, }: {
|
|
14
|
+
ethereum: Eip1193Provider;
|
|
15
|
+
network?: Networkish;
|
|
16
|
+
options?: BrowserProviderOptions;
|
|
17
|
+
config?: BaseConfig;
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Manages and returns the next available nonce for a given address.
|
|
21
|
+
*
|
|
22
|
+
* This method implements a local nonce management system to handle concurrent
|
|
23
|
+
* transactions and potential network delays. It's necessary because:
|
|
24
|
+
* 1. Multiple transactions can be initiated before earlier ones are confirmed.
|
|
25
|
+
* 2. We need to ensure each transaction uses a unique, incrementing nonce.
|
|
26
|
+
*
|
|
27
|
+
* The method works by:
|
|
28
|
+
* - Tracking the last used nonce for each address.
|
|
29
|
+
* - Comparing it with the current network nonce.
|
|
30
|
+
* - Always returning a nonce higher than both the network nonce and the last used nonce.
|
|
31
|
+
*
|
|
32
|
+
* This approach helps prevent nonce conflicts and ensures transactions can be
|
|
33
|
+
* sent in rapid succession without waiting for network confirmation.
|
|
34
|
+
*
|
|
35
|
+
* @param address - The Ethereum address for which to get the next nonce.
|
|
36
|
+
* @returns A Promise that resolves to the next available nonce as a number.
|
|
37
|
+
*/
|
|
38
|
+
private getNextNonce;
|
|
39
|
+
/**
|
|
40
|
+
* Custom method to handle transaction creation, signing, and broadcasting.
|
|
41
|
+
*
|
|
42
|
+
* This method is necessary because:
|
|
43
|
+
* 1. When using Fireblocks to sign a transaction with CONTRACT_CALL,
|
|
44
|
+
* Fireblocks also broadcasts the transaction to the specified chain
|
|
45
|
+
* on the Fireblocks provider configuration.
|
|
46
|
+
* 2. We need to manually handle the transaction creation process instead of
|
|
47
|
+
* delegating everything to Fireblocks, as we need to broadcast it to our
|
|
48
|
+
* own nodes.
|
|
49
|
+
* 3. When populating a transaction (e.g., getting the nonce), we need to make
|
|
50
|
+
* requests with auth headers to our RPC.
|
|
51
|
+
*
|
|
52
|
+
* This custom implementation allows us to control the entire process,
|
|
53
|
+
* from transaction creation to signing and broadcasting. It ensures that
|
|
54
|
+
* the necessary authenticated requests are made when populating the transaction,
|
|
55
|
+
* and that the final transaction is broadcast to our specific nodes.
|
|
56
|
+
*
|
|
57
|
+
* @param payload - The transaction payload to be sent
|
|
58
|
+
* @returns The transaction hash
|
|
59
|
+
*/
|
|
60
|
+
sendTransaction(payload: any): Promise<string | null>;
|
|
61
|
+
private setupInterceptor;
|
|
62
|
+
clone(): SilentDataRollupFireblocksProvider;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { DEBUG_NAMESPACE_SILENTDATA_INTERCEPTOR, SilentDataRollupFireblocksProvider };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BaseConfig } from '@appliedblockchain/silentdatarollup-core';
|
|
2
|
+
import { BrowserProvider, Eip1193Provider, Networkish, BrowserProviderOptions } from 'ethers';
|
|
3
|
+
|
|
4
|
+
declare const DEBUG_NAMESPACE_SILENTDATA_INTERCEPTOR = "fireblocks-web3-provider:silentdata-interceptor";
|
|
5
|
+
|
|
6
|
+
declare class SilentDataRollupFireblocksProvider extends BrowserProvider {
|
|
7
|
+
private lastNonce;
|
|
8
|
+
private ethereum;
|
|
9
|
+
private network;
|
|
10
|
+
private _options;
|
|
11
|
+
private config;
|
|
12
|
+
private baseProvider;
|
|
13
|
+
constructor({ ethereum, network, options, config, }: {
|
|
14
|
+
ethereum: Eip1193Provider;
|
|
15
|
+
network?: Networkish;
|
|
16
|
+
options?: BrowserProviderOptions;
|
|
17
|
+
config?: BaseConfig;
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Manages and returns the next available nonce for a given address.
|
|
21
|
+
*
|
|
22
|
+
* This method implements a local nonce management system to handle concurrent
|
|
23
|
+
* transactions and potential network delays. It's necessary because:
|
|
24
|
+
* 1. Multiple transactions can be initiated before earlier ones are confirmed.
|
|
25
|
+
* 2. We need to ensure each transaction uses a unique, incrementing nonce.
|
|
26
|
+
*
|
|
27
|
+
* The method works by:
|
|
28
|
+
* - Tracking the last used nonce for each address.
|
|
29
|
+
* - Comparing it with the current network nonce.
|
|
30
|
+
* - Always returning a nonce higher than both the network nonce and the last used nonce.
|
|
31
|
+
*
|
|
32
|
+
* This approach helps prevent nonce conflicts and ensures transactions can be
|
|
33
|
+
* sent in rapid succession without waiting for network confirmation.
|
|
34
|
+
*
|
|
35
|
+
* @param address - The Ethereum address for which to get the next nonce.
|
|
36
|
+
* @returns A Promise that resolves to the next available nonce as a number.
|
|
37
|
+
*/
|
|
38
|
+
private getNextNonce;
|
|
39
|
+
/**
|
|
40
|
+
* Custom method to handle transaction creation, signing, and broadcasting.
|
|
41
|
+
*
|
|
42
|
+
* This method is necessary because:
|
|
43
|
+
* 1. When using Fireblocks to sign a transaction with CONTRACT_CALL,
|
|
44
|
+
* Fireblocks also broadcasts the transaction to the specified chain
|
|
45
|
+
* on the Fireblocks provider configuration.
|
|
46
|
+
* 2. We need to manually handle the transaction creation process instead of
|
|
47
|
+
* delegating everything to Fireblocks, as we need to broadcast it to our
|
|
48
|
+
* own nodes.
|
|
49
|
+
* 3. When populating a transaction (e.g., getting the nonce), we need to make
|
|
50
|
+
* requests with auth headers to our RPC.
|
|
51
|
+
*
|
|
52
|
+
* This custom implementation allows us to control the entire process,
|
|
53
|
+
* from transaction creation to signing and broadcasting. It ensures that
|
|
54
|
+
* the necessary authenticated requests are made when populating the transaction,
|
|
55
|
+
* and that the final transaction is broadcast to our specific nodes.
|
|
56
|
+
*
|
|
57
|
+
* @param payload - The transaction payload to be sent
|
|
58
|
+
* @returns The transaction hash
|
|
59
|
+
*/
|
|
60
|
+
sendTransaction(payload: any): Promise<string | null>;
|
|
61
|
+
private setupInterceptor;
|
|
62
|
+
clone(): SilentDataRollupFireblocksProvider;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { DEBUG_NAMESPACE_SILENTDATA_INTERCEPTOR, SilentDataRollupFireblocksProvider };
|