droplinked-web3-kit 0.0.2 β†’ 0.0.4

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.
Files changed (2) hide show
  1. package/README.md +206 -322
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,400 +1,284 @@
1
- # Project Onboarding Guide
2
-
3
- Welcome to the DropLinked Web3 integration library! This document is designed to bring new developers up to speed on how the system is structured, how its core components interact, and how to extend or maintain functionality. It covers architecture, key abstractions, concrete implementations (with a focus on EVM-compatible chains), error handling, configuration, and end-to-end usage examples.
1
+ # Droplinked Web3 Kit β€” Developer Guide πŸš€
4
2
 
5
3
  ---
6
4
 
7
- ## 0. Project Structure
8
-
9
- ```
10
- β”‚ index.ts
11
- β”‚
12
- └───lib
13
- β”‚ web3.ts
14
- β”‚
15
- β”œβ”€β”€β”€chains
16
- β”‚ β”‚ chain-provider.ts
17
- β”‚ β”‚ README.md
18
- β”‚ β”‚
19
- β”‚ β”œβ”€β”€β”€dto
20
- β”‚ β”‚ β”‚ chains.ts
21
- β”‚ β”‚ β”‚
22
- β”‚ β”‚ β”œβ”€β”€β”€configs
23
- β”‚ β”‚ β”‚ chain.config.ts
24
- β”‚ β”‚ β”‚ chainlink-addresses.ts
25
- β”‚ β”‚ β”‚ README.md
26
- β”‚ β”‚ β”‚ web3-config.ts
27
- β”‚ β”‚ β”‚
28
- β”‚ β”‚ β”œβ”€β”€β”€constants
29
- β”‚ β”‚ β”‚ airdrop-abi.ts
30
- β”‚ β”‚ β”‚ chain-abis.ts
31
- β”‚ β”‚ β”‚ chain-constants.ts
32
- β”‚ β”‚ β”‚ chain-structs.ts
33
- β”‚ β”‚ β”‚ README.md
34
- β”‚ β”‚ β”‚
35
- β”‚ β”‚ β”œβ”€β”€β”€errors
36
- β”‚ β”‚ β”‚ chain-errors.ts
37
- β”‚ β”‚ β”‚
38
- β”‚ β”‚ └───interfaces
39
- β”‚ β”‚ airdrop-token.interface.ts
40
- β”‚ β”‚ chain-payment.interface.ts
41
- β”‚ β”‚ chain-provider.interface.ts
42
- β”‚ β”‚ claim-nft-inputs.ts
43
- β”‚ β”‚ deploy-shop.interface.ts
44
- β”‚ β”‚ login-result.interface.ts
45
- β”‚ β”‚ modal-interface.interface.ts
46
- β”‚ β”‚ payment-interface.ts
47
- β”‚ β”‚ record-web3-product.interface.ts
48
- β”‚ β”‚ web3-context.interface.ts
49
- β”‚ β”‚
50
- β”‚ └───providers
51
- β”‚ β”œβ”€β”€β”€evm
52
- β”‚ β”‚ evm-affiliate.ts
53
- β”‚ β”‚ evm-airdrop.ts
54
- β”‚ β”‚ evm-claim-nfts.ts
55
- β”‚ β”‚ evm-constants.ts
56
- β”‚ β”‚ evm-deploy-shop.ts
57
- β”‚ β”‚ evm-login.ts
58
- β”‚ β”‚ evm-payments.ts
59
- β”‚ β”‚ evm-provider.ts
60
- β”‚ β”‚ evm-publish.ts
61
- β”‚ β”‚ evm-record.ts
62
- β”‚ β”‚ evm.helpers.ts
63
- β”‚ β”‚ README.md
64
- β”‚ β”‚
65
- β”‚ β”œβ”€β”€β”€solana
66
- β”‚ β”‚ README.md
67
- β”‚ β”‚ solana-provider.ts
68
- β”‚ β”‚
69
- β”‚ └───unstoppable
70
- β”‚ unstoppable-provider.ts
71
- β”‚
72
- └───wallet-providers
73
- appkit.ts
74
- ```
75
-
5
+ ## Table of Contents
6
+
7
+ 1. Overview
8
+ 2. Core Concepts
9
+ 3. Authentication (Login via Wallet)
10
+ - Metamask | Phantom Wallet (Standard Login)
11
+ - Unstoppable Domains Login
12
+ 4. Recording Products on-chain
13
+ - Record Procedure
14
+ - Custom Errors
15
+ 5. Payments
16
+ - Payment Procedure
17
+ - Supported Chains & Tokens
18
+ 6. Example Flows (End-to-End)
19
+ 7. Notes & Assumptions
20
+ 8. Open Questions (please confirm)
76
21
 
77
22
  ---
78
23
 
79
- ## 1. High-Level Architecture
80
-
81
- At the heart of this library is a **factory** class called `DropWeb3`, which, given a chosen network (Testnet, Mainnet, etc.), exposes a **single entry point** (`web3Instance`) to obtain a configured provider that implements the `IChainProvider` interface. Each provider (e.g., `EVMProvider`, `SolanaProvider`, `UnstoppableProvider`) encapsulates all chain-specific logic, from wallet connection through contract interaction and transaction management.
24
+ ## 1) Overview
82
25
 
83
- The design follows the **Strategy pattern**: calling code never directly references blockchain-specific classes; it only relies on the uniform methods defined by `IChainProvider`. This ensures that adding support for new chains or networks requires zero changes to application-level logic.
26
+ **Droplinked Web3 Kit** exposes a single entry class `DropWeb3` configured with an environment `Network` (e.g., `TESTNET`, `MAINNET`) and a `shopId` (as shown in the examples). From that instance, you create a **provider** through `web3Instance(...)` that is specialized by `Web3Actions` such as `LOGIN`, `RECORD`, or `PAYMENT`. Subsequent methods (e.g., `walletLogin`, `unstoppableLogin`, `recordProduct`, `payment`) execute the corresponding flow.
84
27
 
85
28
  ---
86
29
 
87
- ## 2. Core Interfaces and Types
88
-
89
- ### 2.1 IChainProvider Interface
90
-
91
- Defines the contract every chain provider must fulfill. Key methods:
30
+ ## 2) Core Concepts
92
31
 
93
- - **`setAxiosInstance(axiosInstance: KyInstance)`**: Inject a custom HTTP client for backend calls (e.g., metadata upload, address lookup).
94
- - **`walletLogin()`**: Trigger user login via wallet, returning `{ address, signature, nonce, timestamp }`.
95
- - **`deployShop(shopDetails: IDeployShop)`**: Deploy a shop smart contract, returning addresses and constructor args.
96
- - **`recordProduct(productData: IProductDetails, skuData: ISKUDetails[])`**: Mint NFTs and register product metadata with your shop contract.
97
- - **`publishRequest(productId: Uint256, shopAddress: EthAddress)`**: Request affiliate permission to publish a product.
98
- - **`approveRequest(requestId: Uint256, shopAddress: EthAddress)`** / **`disapproveRequest(...)`**: Approve or disapprove affiliate requests.
99
- - **`payment(data: IPaymentInputs)`**: Execute a payment, handling token approvals and transfers.
100
- - **`customPayment(data: IChainPayment)`**: Low-level payment via proxy contracts.
101
- - **`paymentWithToken(receiver: string, amount: number, tokenAddress: string)`**: Direct token transfer.
102
- - **`claimNFTs(data: ClaimNFTInputs)`**: Process NFT claim transactions.
103
- - **`executeAirdrop(airdropId: string)`**: Run batch airdrops of NFTs or tokens.
104
- - **Chaining setters**: `setAddress`, `setWallet`, `setModal`, `setNFTContractAddress`, `setShopContractAddress`, `setWalletModal` – provide a *fluent API* to configure context before invoking actions.
105
- - **`disconnect()`**: Cleanly disconnect from the wallet or provider.
32
+ - **DropWeb3:** Root object created per environment + shopId.
33
+ - **Web3Actions:** Selects the high-level intent: `LOGIN`, `RECORD`, `PAYMENT`.
34
+ - **Chain & ChainWallet:** Choose the blockchain (e.g., `POLYGON`, `BINANCE`) and wallet (e.g., `Metamask`, `UnstoppableDomains`, `Phantom`) for the action.
35
+ - **Provider:** Returned by `web3Instance(...)`, it exposes the concrete method(s) for the chosen action (e.g., `walletLogin`, `unstoppableLogin`, `recordProduct`, `payment`).
106
36
 
107
- All methods return Promises, and setter methods return `this` for easy chaining.
37
+ ---
108
38
 
109
- ### 2.2 Web3ChainConfig & Web3Actions
39
+ ## 3) Authentication (Login via Wallet) πŸ”
110
40
 
111
- Controls how `DropWeb3.web3Instance()` configures your provider:
41
+ ### 3.1 Metamask (Standard Login)
112
42
 
113
- - **`method: Web3Actions`**: One of `LOGIN`, `DEPLOY`, `RECORD_AFFILIATE`, `PAYMENT`, `CLAIM`, `AIRDROP`.
114
- - **`chain: Chain`** and **`network: Network`**: Specify which blockchain and sub-network to target.
115
- - **`preferredWallet: ChainWallet | ChainWallet[]`**: Wallet(s) to prompt (e.g., MetaMask, Phantom, Unstoppable Domains).
116
- - **`userAddress`, `nftContractAddress`, `shopContractAddress`**: Provide runtime data required by certain actions.
117
- - **`modalInterface`**: Inject a UI layer for status, confirmations, or error dialogues.
43
+ **Purpose:** Obtain user address and signature by prompting the user’s wallet.
44
+ **Flow:**
118
45
 
119
- The factory interprets these configs to instantiate and configure the correct provider.
46
+ 1) Instantiate `DropWeb3` with `Network` and token.
47
+ 2) Create a `LOGIN` provider with your preferred wallet (`Metamask` | `Phantom`).
48
+ 3) Call `walletLogin()`.
120
49
 
121
- ### 2.3 DroplinkedChainConfig
50
+ **ChainWallets**
122
51
 
123
- A lightweight internal structure used by helper functions. Contains:
52
+ ```
53
+ Metamask | CoinBase | CasperWallet (Deprecated) | Phantom | BaseSmartWallet | UnstoppableDomains
54
+ ```
124
55
 
125
- - **`provider: ethers.BrowserProvider`** – low-level RPC connection.
126
- - **`chain: Chain`, `network: Network`, `userAddress: EthAddress`** – routing details.
127
- - **`axiosInstance: KyInstance`** – API client.
128
- - **`modalInterface: ModalInterface`** – user feedback hook.
129
- - **`gasPredictable: boolean`** – hint for gas estimation strategies.
56
+ **Chains**
57
+
58
+ ```js
59
+ export enum Chain {
60
+ CASPER = 'CASPER',
61
+ POLYGON = 'POLYGON',
62
+ BINANCE = 'BINANCE',
63
+ STACKS = 'STACKS',
64
+ XRPLSIDECHAIN = 'XRPLSIDECHAIN',
65
+ NEAR = 'NEAR',
66
+ SKALE = 'SKALE',
67
+ BASE = 'BASE',
68
+ LINEA = 'LINEA',
69
+ ETH = 'ETH',
70
+ SOLANA = 'SOLANA',
71
+ REDBELLY = 'REDBELLY',
72
+ UNSTOPPABLE = 'UNSTOPPABLE',
73
+ BITLAYER = 'BITLAYER',
74
+ }
75
+ ```
130
76
 
131
- ---
77
+ **Example:**
132
78
 
133
- ## 3. The DropWeb3 Factory
79
+ ```ts
80
+ // Create web3 object
81
+ const web3 = new DropWeb3(Network.TESTNET, shopId);
134
82
 
135
- Implemented in `chain-provider.ts`, the `DropWeb3` class:
83
+ // Create the chain provider for login
84
+ const chainProvider = await web3.web3Instance({
85
+ method: Web3Actions.LOGIN,
86
+ preferredWallet: ChainWallet.Metamask,
87
+ });
136
88
 
137
- 1. **Constructor**: Accepts a `Network` enum; initializes a `ky` client pointing to dev or prod API endpoints.
138
- 2. **chainMapping**: A nested dictionary mapping each `Chain` and `Network` combination to a specific provider instance.
139
- 3. **`web3Instance(config: Web3ChainConfig)`**:
140
- - Validates that an implementation exists for the requested chain/network.
141
- - Retrieves or constructs a modal via `AppKitProvider`.
142
- - Calls chaining setters on the provider instance: `.setAddress()`, `.setWallet()`, `.setModal()`, `.setAxiosInstance()`.
143
- - Returns the configured `IChainProvider`.
89
+ // Prompt wallet & get login result
90
+ const loginData = await chainProvider.walletLogin();
144
91
 
145
- **Usage Example**:
146
- ```ts
147
- const factory = new DropWeb3(Network.TESTNET);
148
- const provider = factory.web3Instance({
149
- method: Web3Actions.DEPLOY,
150
- chain: Chain.ETH,
151
- userAddress: '0xabc...'
92
+ console.log({
93
+ address: loginData.address,
94
+ date: loginData.date,
95
+ nonce: loginData.nonce,
96
+ signature: loginData.signature,
152
97
  });
153
98
  ```
154
99
 
155
- ---
156
-
157
- ## 4. Implementation: EVMProvider
158
-
159
- Located at `lib/chains/providers/evm/evm-provider.ts`, `EVMProvider`:
160
-
161
- ### 4.1 Construction & Configuration
162
-
163
- - **Constructor**
164
- ```ts
165
- constructor(chain: Chain, network: Network, gasPredictable: boolean) { … }
166
- ```
167
- - Initializes `chain`, `network`, `gasPredictable`.
168
- - Sets default `axiosInstance`, `modalInterface`, and `address = ZERO_ADDRESS`.
169
-
170
- - **Chaining Setters**: `setAxiosInstance()`, `setWalletModal()`, `setNFTContractAddress()`, `setShopContractAddress()`, `setWallet()`, `setModal()`, `setAddress()`.
100
+ **Expected fields:** `address`, `date`, `nonce`, `signature`.
171
101
 
172
- ### 4.2 Connection Management
102
+ ### 3.2 Unstoppable Domains Login
173
103
 
174
- - **`getEthersProvider()`**:
175
- 1. Checks `modal.getProvider('eip155')`.
176
- 2. Uses `modal.connect('eip155')` if needed.
177
- 3. Returns `ethers.BrowserProvider`.
104
+ **Purpose:** Authenticate with Unstoppable Domains using a UD key and redirect origin.
105
+ **Flow:**
178
106
 
179
- - **`disconnect()`**: Calls `modal.disconnect('eip155')` until none remain.
107
+ 1) Instantiate `DropWeb3`.
108
+ 2) Create a `LOGIN` provider with `ChainWallet.UnstoppableDomains`.
109
+ 3) Call `unstoppableLogin(udKey, origin)`.
180
110
 
181
- ### 4.3 Core Feature Methods
111
+ **Example:**
182
112
 
183
- #### 4.3.1 Wallet Login
184
- 1. `getEthersProvider()`
185
- 2. Request accounts.
186
- 3. Switch or add chain as needed.
187
- 4. Request SKALE fuel if applicable.
188
- 5. Fetch nonce, sign message.
189
- 6. Return `{ address, signature, nonce, timestamp }`.
190
-
191
- #### 4.3.2 Shop Deployment
192
- Delegates to `deployEVMShop()`:
193
- 1. Build constructor args.
194
- 2. Fetch bytecode via `getShopByteCode()`.
195
- 3. Estimate gas and deploy via Ethers.js.
196
- 4. Wait for `ShopDeployed` event.
197
- 5. Return `{ shopAddress, metadataURI }`.
198
-
199
- #### 4.3.3 Product Recording (NFT Minting)
200
- Calls `recordProduct()`:
201
- 1. Upload metadata for each SKU.
202
- 2. Prepare data: `{ tokenURI, quantity, price }`.
203
- 3. Batch mint NFTs.
204
- 4. Return `{ transactionHash, mintedIds }`.
205
-
206
- #### 4.3.4 Affiliate Publishing Workflows
207
- - **publishRequest()**: Sends `requestAffiliate()` transaction; waits for `AffiliateRequested` event.
208
- - **approveRequest()/disapproveRequest()**: Executes `approve(requestId)` or `disapprove(requestId)` and handles common errors.
113
+ ```ts
114
+ const web3 = new DropWeb3(Network.TESTNET, shopId);
209
115
 
210
- #### 4.3.5 Payments Processing
211
- - **`payment()`**: Validates inputs, builds `DroplinkedChainConfig` and context, calls `droplinked_payment()`, simulates via static call, estimates gas (+5%), sends transaction.
212
- - **`customPayment()`**: Direct proxy contract call.
213
- - **`paymentWithToken()`**: Direct ERC20 transfer.
116
+ const chainProvider = await web3.web3Instance({
117
+ method: Web3Actions.LOGIN,
118
+ preferredWallet: ChainWallet.UnstoppableDomains,
119
+ });
214
120
 
215
- #### 4.3.6 NFT Claiming
216
- `claimNFTs()` calls bulk `claimPurchase()` on shop contract; returns transaction hash.
121
+ const loginData = await chainProvider.unstoppableLogin(
122
+ 'de81c772-62be-45ed-8d0b-103abfec2ab8', // UD Key
123
+ window.location.origin
124
+ );
217
125
 
218
- #### 4.3.7 Airdrops
219
- `executeAirdrop()`:
220
- 1. Fetch recipients and token lists.
221
- 2. Batch-call `airdropTokens()`.
222
- 3. Return list of transaction hashes.
126
+ console.log({ loginData });
127
+ ```
223
128
 
224
129
  ---
225
130
 
226
- ## 5. Supporting Modules & Utilities
131
+ ## 4) Recording Products on-chain 🧾
227
132
 
228
- ### 5.1 Constants & Structs
229
- - **`chain-constants.ts`**: ZERO_ADDRESS, network IDs.
230
- - **`chain-structs.ts`**: Types (`EthAddress`, `Uint256`, etc.)
133
+ ### 4.1 Record Procedure
231
134
 
232
- ### 5.2 ABI Definitions
233
- - Stored in `chain-abis/`.
234
- - Helper getters like `getERC20TokenTransferABI()`.
135
+ **Purpose:** Record a product to a specific blockchain for a given shop.
136
+ **Inputs (from your example):**
235
137
 
236
- ### 5.3 Chain Config Fetchers
237
- In `chain.config.ts`:
238
- - `getDeployerAddress()`, `getProxyAddress()`, `getFundsProxy()`, `getAirdropAddress()`.
138
+ - `blockchain` (string name matching `Chain[...]`)
139
+ - `productId`
140
+ - `accountAddress` (can be `''` to trigger wallet connect)
141
+ - `shopId`
142
+ - `Network` selection (TESTNET/MAINNET)
143
+ - `preferredWallet` (e.g., `Metamask`)
239
144
 
240
- ### 5.4 Error Classes
241
- From `chain-errors.ts`:
242
- - Wallet errors: `MetaMaskNotFoundException`, etc.
243
- - Chain errors: `ChainNotImplementedException`, etc.
244
- - Payment errors: `InsufficientBalanceException`, etc.
145
+ **Flow:**
245
146
 
246
- ---
247
-
248
- ## 6. Error Handling Patterns
249
-
250
- 1. Wrap external calls in `try/catch`.
251
- 2. Map errors to domain-specific exceptions.
252
- 3. Use `modalInterface.showError()` for UI feedback.
253
- 4. Retry transient failures (up to 2 attempts, exponential backoff).
254
- 5. Validate event logs; throw `UnexpectedContractResponse` if missing.
255
-
256
- ---
147
+ 1) Instantiate `DropWeb3` with environment and `shopId`.
148
+ 2) Create a `RECORD` provider for the desired chain.
149
+ 3) Call `recordProduct(productId)` and handle the response.
257
150
 
258
- ## 7. Setup, Configuration & Usage Examples
151
+ **Example:**
259
152
 
260
- **Initialize factory**:
261
153
  ```ts
262
- import { DropWeb3 } from './lib/chains/chain-provider';
263
- import { Network, Web3Actions, Chain, ChainWallet } from './lib/chains/dto/configs/web3-config';
154
+ const blockchain = "POLYGON";
155
+ const productId = "your-product-id";
156
+ const accountAddress = "user-wallet-address"; // empty string -> prompts wallet connect
157
+ const shopId = "your-shop-id";
158
+
159
+ const web3 = new DropWeb3(
160
+ appDevelopment ? Network.TESTNET : Network.MAINNET,
161
+ shopId
162
+ );
163
+
164
+ const provider = await web3.web3Instance({
165
+ method: Web3Actions.RECORD,
166
+ chain: Chain[blockchain],
167
+ preferredWallet: ChainWallet.Metamask,
168
+ userAddress: accountAddress, // if '', user is prompted to connect
169
+ });
264
170
 
265
- const web3Factory = new DropWeb3(Network.TESTNET);
171
+ let record: RecordResponse = await provider.recordProduct(productId);
172
+ return record;
266
173
  ```
267
174
 
268
- **Login**:
269
- ```ts
270
- const loginProvider = web3Factory.web3Instance({
271
- method: Web3Actions.LOGIN,
272
- preferredWallet: ChainWallet.Metamask
273
- });
274
- const { address, signature } = await loginProvider.walletLogin();
275
- ```
175
+ ### 4.2 Custom Errors (import & check as needed)
276
176
 
277
- **Deploy Shop**:
278
- ```ts
279
- const web3 = new DropWeb3(appDevelopment ? Network.TESTNET : Network.MAINNET);
280
- const chainInstance = web3.web3Instance({
281
- method: Web3Actions.DEPLOY,
282
- preferredWallet: preferredWallets,
283
- chain: Chain.BASE,
284
- userAddress: "0x...",
285
- });
286
- const shop = chainInstance.deployShop({
287
- shopAddress: "...",
288
- shopDescription: "...",
289
- shopLogo: "...",
290
- shopName: "..."
291
- })
292
- console.log(shop.deployedNFTAddress, shop.deployedShopAddress, shop.transactionHash);
293
- ```
177
+ - `ChainNotImplementedException`
178
+ - `Unauthorized`
179
+ - `FieldNotFound` (missing `nftContractAddress`/`shopContractAddress`)
180
+ - `Web3CallbackFailed`
181
+ - `MetadataUploadFailedException`
182
+ - `WalletNotFoundException`
183
+ - `AccountAccessDeniedException`
184
+ - `NoAccountsFoundException`
185
+ - `SignatureRequestDeniedException`
186
+ - `ChainSwitchException`
187
+ - `UserDeniedException`
294
188
 
189
+ > Use these to provide user-friendly messages and remediation (e.g., ask to install wallet, approve access, switch network).
295
190
 
296
191
  ---
297
192
 
298
- ## 8. Extending to New Chains
193
+ ## 5) Payments πŸ’³
299
194
 
300
- 1. Create `NewChainProvider implements IChainProvider` under `lib/chains/providers/newchain/`.
301
- 2. Implement all interface methods using the chain's SDK.
302
- 3. Add to `chainMapping` in `chain-provider.ts`.
303
- 4. Include any new ABI or config files.
304
- 5. Write integration tests covering all methods.
195
+ ### 5.1 Payment Procedure
305
196
 
306
- ---
197
+ **Purpose:** Execute a crypto payment for an order using a specified token and chain.
198
+ **Inputs (from your example):**
307
199
 
308
- ## 9. Best Practices & Recommendations
200
+ - `shopId`
201
+ - `orderId`
202
+ - `paymentToken` (enum)
203
+ - `paymentType` (enum `Chain`)
204
+ - `userAddress` (optional: empty string will prompt wallet connect)
309
205
 
310
- - **Fluent Configuration**: Always chain `.setWallet()`, `.setModal()`, `.setAxiosInstance()` before actions.
311
- - **Await Confirmations**: Use `tx.wait()` to ensure on-chain finality.
312
- - **Error Granularity**: Handle domain-specific exceptions for better UX.
313
- - **Avoid Hardcoding**: Use config fetchers; do not embed addresses in code.
314
- - **Testing**: Cover actions on both Testnet and Mainnet.
315
- - **Security**: Always verify signatures server-side.
206
+ **Flow:**
316
207
 
317
- ---
208
+ 1) Instantiate `DropWeb3` with environment and `shopId`.
209
+ 2) Create a `PAYMENT` provider for the target chain.
210
+ 3) Call `payment({ orderID, paymentToken, paymentType })`.
318
211
 
319
- *Welcome aboard! Use this guide as your roadmap to explore, debug, and extend the DropLinked integration library.*
212
+ **Example:**
320
213
 
214
+ ```ts
215
+ import {
216
+ Chain,
217
+ ChainWallet,
218
+ DropWeb3,
219
+ Network,
220
+ PaymentTokens,
221
+ Web3Actions,
222
+ } from 'droplinked-web3-kit';
223
+
224
+ const shopId = '66d47d965744cb21dac659ab';
225
+ const orderId = '5a4fc3e56134cb23cba014dc';
226
+ const paymentMethod = 'USDC';
227
+ const paymentType = 'BINANCE';
228
+
229
+ const web3 = new DropWeb3(Network.TESTNET, shopId);
230
+
231
+ const instance = await web3.web3Instance({
232
+ method: Web3Actions.PAYMENT,
233
+ chain: Chain[paymentType],
234
+ preferredWallet: ChainWallet.Metamask,
235
+ userAddress: '0xYourWalletAddressHere', // or '' to prompt connect
236
+ });
321
237
 
322
- ## 10. Project Entry Points
238
+ const result = await instance.payment({
239
+ orderID: orderId,
240
+ paymentToken: PaymentTokens[paymentMethod],
241
+ paymentType: Chain[paymentType],
242
+ });
323
243
 
324
- ### 10.1 `index.ts`
244
+ console.log({
245
+ orderID: result.orderID,
246
+ cryptoAmount: result.cryptoAmount,
247
+ transactionHash: result.transactionHash,
248
+ transactionId: result.transactionId,
249
+ });
250
+ ```
325
251
 
326
- The entry point of the library re-exports core modules to simplify imports:
252
+ **Returned fields:** typical payment metadata like `cryptoAmount`, `transactionHash`, `transactionId` (names based on your example).
327
253
 
328
- ```ts
329
- // index.ts
330
- export * from './lib/web3';
331
- ```
254
+ ### 5.2 Supported Enums
332
255
 
333
- This allows consumers to import everything via:
256
+ **Payment Tokens**
334
257
 
335
- ```ts
336
- import { DropWeb3, Web3Actions, Chain, Network } from 'droplinked-sdk';
258
+ ```
259
+ ETH | RBNT | SOL | USDC | USDT | MEW | BNB | MATIC | CSPR | PARAM | BDC | BTC
337
260
  ```
338
261
 
339
- ### 10.2 `web3.ts`
340
-
341
- The `web3.ts` file consolidates and re-exports all sub-modules:
262
+ **Chains**
342
263
 
343
- ```ts
344
- import { ZERO_ADDRESS } from './chains/dto/constants/chain-constants';
345
-
346
- export * from './chains/chain-provider';
347
- export * from './chains/providers/evm/evm-login';
348
- export * from './chains/dto/errors/chain-errors';
349
- export * from './chains/dto/constants/chain-structs';
350
- export * from './chains/dto/chains';
351
- export * from './chains/dto/interfaces/modal-interface.interface';
352
- export * from './chains/dto/configs/chain.config';
353
- export * from './chains/dto/configs/web3-config';
354
- export * from './chains/dto/interfaces/chain-provider.interface';
355
- export * from './chains/dto/interfaces/airdrop-token.interface';
356
- export * from './chains/dto/interfaces/claim-nft-inputs';
357
- export * from './chains/dto/interfaces/deploy-shop.interface';
358
- export * from './chains/dto/interfaces/record-web3-product.interface';
359
- export * from './chains/dto/interfaces/web3-context.interface';
360
- export { ZERO_ADDRESS };
264
+ ```
265
+ CASPER | POLYGON | BINANCE | STACKS | XRPLSIDECHAIN | NEAR | SKALE | BASE | LINEA | ETH | SOLANA | REDBELLY | UNSTOPPABLE | BITLAYER
361
266
  ```
362
267
 
363
- This centralized export ensures that all types, interfaces, and implementations are available through a single import path.
268
+ Use `PaymentTokens[<TOKEN>]` and `Chain[<CHAIN>]` for type-safe invocation.
364
269
 
365
- ## 11. DTO Layer & File Structure
270
+ ---
366
271
 
367
- Under `lib/chains/dto`, the Data Transfer Objects (DTOs) and configuration files define the structural contracts:
272
+ ## 6) Example Flows (End-to-End) 🧭
368
273
 
369
- ```
370
- lib/chains/dto
371
- β”œβ”€β”€ chains.ts
372
- β”œβ”€β”€ configs
373
- β”‚ β”œβ”€β”€ chain.config.ts
374
- β”‚ └── web3-config.ts
375
- β”œβ”€β”€ constants
376
- β”‚ β”œβ”€β”€ chain-constants.ts
377
- β”‚ └── chain-structs.ts
378
- β”œβ”€β”€ errors
379
- β”‚ └── chain-errors.ts
380
- └── interfaces
381
- β”œβ”€β”€ airdrop-token.interface.ts
382
- β”œβ”€β”€ chain-provider.interface.ts
383
- β”œβ”€β”€ chain-payment.interface.ts
384
- β”œβ”€β”€ claim-nft-inputs.ts
385
- β”œβ”€β”€ deploy-shop.interface.ts
386
- β”œβ”€β”€ modal-interface.interface.ts
387
- β”œβ”€β”€ record-web3-product.interface.ts
388
- └── web3-context.interface.ts
389
- ```
274
+ ### 6.1 Login β†’ Record
390
275
 
391
- - **`chains.ts`**: Defines the `Chain` enum (e.g., ETH, POLYGON) and related types.
392
- - **`chain.config.ts`**: Provides `getDeployerAddress`, `getProxyAddress`, and other address-fetching utilities.
393
- - **`web3-config.ts`**: Exports `Web3Actions` enum and `Web3ChainConfig` interface used by the `DropWeb3` factory.
394
- - **`chain-constants.ts`**: Common constants like `ZERO_ADDRESS` and retry settings.
395
- - **`chain-structs.ts`**: Strong-type wrappers for on-chain data (e.g., `EthAddress`, `Uint256`).
396
- - **`chain-errors.ts`**: Domain-specific error classes covering wallet, RPC, and contract errors.
397
- - **Interfaces**: Define method signatures and data shapes for all features (login, deployment, recording, payments, airdrops, modal interactions).
276
+ 1) `LOGIN` via Metamask (`walletLogin`) to obtain `address`.
277
+ 2) `RECORD` with `userAddress` set to the login address.
278
+ 3) `recordProduct(productId)` and store the `RecordResponse` in your system.
398
279
 
399
- By understanding this DTO layer, developers can see how configuration and data shapes flow through the factory into each provider.
280
+ ### 6.2 Login β†’ Pay
400
281
 
282
+ 1) `LOGIN` to obtain `address`.
283
+ 2) `PAYMENT` with `userAddress` or let it prompt the wallet.
284
+ 3) `payment({ orderID, paymentToken, paymentType })`, then persist `transactionHash`/`transactionId`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "droplinked-web3-kit",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "dependencies": {
5
5
  "ethers": "^5.7.2",
6
6
  "ky": "^1.7.2",