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.
- package/README.md +206 -322
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,400 +1,284 @@
|
|
|
1
|
-
#
|
|
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
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
-
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
-
-
|
|
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
|
-
|
|
37
|
+
---
|
|
108
38
|
|
|
109
|
-
|
|
39
|
+
## 3) Authentication (Login via Wallet) π
|
|
110
40
|
|
|
111
|
-
|
|
41
|
+
### 3.1 Metamask (Standard Login)
|
|
112
42
|
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
50
|
+
**ChainWallets**
|
|
122
51
|
|
|
123
|
-
|
|
52
|
+
```
|
|
53
|
+
Metamask | CoinBase | CasperWallet (Deprecated) | Phantom | BaseSmartWallet | UnstoppableDomains
|
|
54
|
+
```
|
|
124
55
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
79
|
+
```ts
|
|
80
|
+
// Create web3 object
|
|
81
|
+
const web3 = new DropWeb3(Network.TESTNET, shopId);
|
|
134
82
|
|
|
135
|
-
|
|
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
|
-
|
|
138
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
###
|
|
102
|
+
### 3.2 Unstoppable Domains Login
|
|
173
103
|
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
107
|
+
1) Instantiate `DropWeb3`.
|
|
108
|
+
2) Create a `LOGIN` provider with `ChainWallet.UnstoppableDomains`.
|
|
109
|
+
3) Call `unstoppableLogin(udKey, origin)`.
|
|
180
110
|
|
|
181
|
-
|
|
111
|
+
**Example:**
|
|
182
112
|
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
116
|
+
const chainProvider = await web3.web3Instance({
|
|
117
|
+
method: Web3Actions.LOGIN,
|
|
118
|
+
preferredWallet: ChainWallet.UnstoppableDomains,
|
|
119
|
+
});
|
|
214
120
|
|
|
215
|
-
|
|
216
|
-
|
|
121
|
+
const loginData = await chainProvider.unstoppableLogin(
|
|
122
|
+
'de81c772-62be-45ed-8d0b-103abfec2ab8', // UD Key
|
|
123
|
+
window.location.origin
|
|
124
|
+
);
|
|
217
125
|
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
##
|
|
131
|
+
## 4) Recording Products on-chain π§Ύ
|
|
227
132
|
|
|
228
|
-
###
|
|
229
|
-
- **`chain-constants.ts`**: ZERO_ADDRESS, network IDs.
|
|
230
|
-
- **`chain-structs.ts`**: Types (`EthAddress`, `Uint256`, etc.)
|
|
133
|
+
### 4.1 Record Procedure
|
|
231
134
|
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
- `
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
151
|
+
**Example:**
|
|
259
152
|
|
|
260
|
-
**Initialize factory**:
|
|
261
153
|
```ts
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
171
|
+
let record: RecordResponse = await provider.recordProduct(productId);
|
|
172
|
+
return record;
|
|
266
173
|
```
|
|
267
174
|
|
|
268
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
##
|
|
193
|
+
## 5) Payments π³
|
|
299
194
|
|
|
300
|
-
1
|
|
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
|
-
|
|
200
|
+
- `shopId`
|
|
201
|
+
- `orderId`
|
|
202
|
+
- `paymentToken` (enum)
|
|
203
|
+
- `paymentType` (enum `Chain`)
|
|
204
|
+
- `userAddress` (optional: empty string will prompt wallet connect)
|
|
309
205
|
|
|
310
|
-
|
|
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
|
-
|
|
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
|
-
|
|
238
|
+
const result = await instance.payment({
|
|
239
|
+
orderID: orderId,
|
|
240
|
+
paymentToken: PaymentTokens[paymentMethod],
|
|
241
|
+
paymentType: Chain[paymentType],
|
|
242
|
+
});
|
|
323
243
|
|
|
324
|
-
|
|
244
|
+
console.log({
|
|
245
|
+
orderID: result.orderID,
|
|
246
|
+
cryptoAmount: result.cryptoAmount,
|
|
247
|
+
transactionHash: result.transactionHash,
|
|
248
|
+
transactionId: result.transactionId,
|
|
249
|
+
});
|
|
250
|
+
```
|
|
325
251
|
|
|
326
|
-
|
|
252
|
+
**Returned fields:** typical payment metadata like `cryptoAmount`, `transactionHash`, `transactionId` (names based on your example).
|
|
327
253
|
|
|
328
|
-
|
|
329
|
-
// index.ts
|
|
330
|
-
export * from './lib/web3';
|
|
331
|
-
```
|
|
254
|
+
### 5.2 Supported Enums
|
|
332
255
|
|
|
333
|
-
|
|
256
|
+
**Payment Tokens**
|
|
334
257
|
|
|
335
|
-
```
|
|
336
|
-
|
|
258
|
+
```
|
|
259
|
+
ETH | RBNT | SOL | USDC | USDT | MEW | BNB | MATIC | CSPR | PARAM | BDC | BTC
|
|
337
260
|
```
|
|
338
261
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
The `web3.ts` file consolidates and re-exports all sub-modules:
|
|
262
|
+
**Chains**
|
|
342
263
|
|
|
343
|
-
```
|
|
344
|
-
|
|
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
|
-
|
|
268
|
+
Use `PaymentTokens[<TOKEN>]` and `Chain[<CHAIN>]` for type-safe invocation.
|
|
364
269
|
|
|
365
|
-
|
|
270
|
+
---
|
|
366
271
|
|
|
367
|
-
|
|
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
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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
|
-
|
|
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`.
|