@verified-network/verified-sdk 1.5.7 → 1.5.8
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 +144 -4
- package/dist/contract/index.js +17 -19
- package/dist/utils/constants.js +5 -3
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -24,9 +24,9 @@ Default providers are available for networks like: mainnet/homestead, ropsten, s
|
|
|
24
24
|
|
|
25
25
|
```
|
|
26
26
|
const {Provider} = require('@verified-network/verified-sdk');
|
|
27
|
-
const defaultProvider = '
|
|
27
|
+
const defaultProvider = 'sepolia' // or any other default provider network of your choice.
|
|
28
28
|
Network/chain id(number) can be used in place of network name, for example:
|
|
29
|
-
const defaultProvider =
|
|
29
|
+
const defaultProvider = 11155111 // where number 11155111 is chain id for sepolia, any other chain id of default provider network can be used.
|
|
30
30
|
let walletWithProvider = wallet.setProvider(
|
|
31
31
|
Provider.defaultProvider(defaultProvider)
|
|
32
32
|
)
|
|
@@ -38,9 +38,9 @@ Verified Sdk supports Infura and Alchemy to provide custom providers for any net
|
|
|
38
38
|
|
|
39
39
|
```
|
|
40
40
|
const {Provider} = require('@verified-network/verified-sdk');
|
|
41
|
-
const network = '
|
|
41
|
+
const network = 'sepolia' // or any other network of your choice.
|
|
42
42
|
Network/chain id(number) can be used in place of network name, for example:
|
|
43
|
-
const network =
|
|
43
|
+
const network = 11155111 // where number 11155111 is chain id for sepolia, any other chain id can be used.
|
|
44
44
|
//For infura; to get api key and enable networks checout: https://www.infura.io/
|
|
45
45
|
const INFURA_API_KEY = 'your infura api key'
|
|
46
46
|
let walletWithProvider = wallet.setProvider(
|
|
@@ -117,6 +117,146 @@ Where, options = {gasPrice: XXX, gasLimit: YYY}
|
|
|
117
117
|
2. Create a wallet instance and fund it
|
|
118
118
|
3. Create instances of the Contract that you want to interact with using the above wallet and call their functions.
|
|
119
119
|
|
|
120
|
+
# Common Error(s) with Verified Sdk integration with Dapp
|
|
121
|
+
|
|
122
|
+
Due to webpack version > 5 that no longer includes NodeJS polyfills by default, it is causing issues for developers that use React(create-react-app), React-native, Vite with webpack version > 5 to build applications with web3.js, ethers.js, alchemy libraries e.t.c. Many of this libraries and dependencies are used by Verified Sdk.
|
|
123
|
+
|
|
124
|
+
There are various ways to solve this error, from updating webpack config to babel config e.t.c. and can be overwhelming for developers. Verified Network Team recommend ed using best solutions that are easy to use and beginner friendly.
|
|
125
|
+
|
|
126
|
+
# How to resolve React error(s) with Verified Sdk integration
|
|
127
|
+
|
|
128
|
+
Step 1: Install react-app-rewired
|
|
129
|
+
with npm: `npm install --save-dev react-app-rewired`
|
|
130
|
+
with yarn: `yarn add --dev react-app-rewired`
|
|
131
|
+
|
|
132
|
+
Step 2: Install needed dependencies
|
|
133
|
+
// with npm:
|
|
134
|
+
`npm install --save-dev crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process`
|
|
135
|
+
// with yarn:
|
|
136
|
+
`yarn add crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process`
|
|
137
|
+
|
|
138
|
+
note: the above dependencies are needed dependencies to make verified sdk works, more dependencies can be added to handle any other nodeJs polyfills error.
|
|
139
|
+
|
|
140
|
+
Step 3: Override create-react-app webpack config file
|
|
141
|
+
In the root folder of your project, create a new file called 'config-overrides.js', and add the following code to it:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
const webpack = require("webpack");
|
|
145
|
+
module.exports = function override(config) {
|
|
146
|
+
const fallback = config.resolve.fallback || {};
|
|
147
|
+
Object.assign(fallback, {
|
|
148
|
+
crypto: require.resolve("crypto-browserify"),
|
|
149
|
+
stream: require.resolve("stream-browserify"),
|
|
150
|
+
assert: require.resolve("assert"),
|
|
151
|
+
http: require.resolve("stream-http"),
|
|
152
|
+
https: require.resolve("https-browserify"),
|
|
153
|
+
os: require.resolve("os-browserify"),
|
|
154
|
+
url: require.resolve("url"),
|
|
155
|
+
path: require.resolve("path-browserify"),
|
|
156
|
+
fs: false, //assumed fs module will not be used(to use fs module download dependency to handle it)
|
|
157
|
+
});
|
|
158
|
+
config.plugins = (config.plugins || []).concat([
|
|
159
|
+
new webpack.ProvidePlugin({
|
|
160
|
+
process: "process/browser",
|
|
161
|
+
Buffer: ["buffer", "Buffer"],
|
|
162
|
+
}),
|
|
163
|
+
]);
|
|
164
|
+
config.module.rules = [
|
|
165
|
+
...config.module.rules,
|
|
166
|
+
{
|
|
167
|
+
test: /\.m?js/,
|
|
168
|
+
resolve: {
|
|
169
|
+
fullySpecified: false,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
]; // rules are optional can be customised to fit your usecase
|
|
173
|
+
config.resolve.fallback = fallback;
|
|
174
|
+
config.ignoreWarnings = [/Failed to parse source map/]; // optional can be customised to fit your usecase
|
|
175
|
+
return config;
|
|
176
|
+
};
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
This 'config-overrides.js' code snippet is telling webpack how to resolve the missing dependencies that are needed to support web3, ethers libraries and wallet providers in the browser/server side.
|
|
180
|
+
|
|
181
|
+
Step 4: Override package.json to use react-app-rewired
|
|
182
|
+
Within the package.json file, replace react-scripts with react-app-rewired scripts for 'start', 'build', 'test'
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
"scripts": {
|
|
186
|
+
"start": "react-app-rewired start",
|
|
187
|
+
"build": "react-app-rewired build",
|
|
188
|
+
"test": "react-app-rewired test",
|
|
189
|
+
"eject": "react-scripts eject"
|
|
190
|
+
},
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
note: start changed from "react-scripts start" to "react-app-rewired start", build from "react-scripts build" to "react-app-rewired build" and test from "react-scripts test" to "react-app-rewired test" while eject remains the same.
|
|
194
|
+
|
|
195
|
+
The polyfill node core module error should be fixed any missing NodeJS polyfills should be included in your app, and your app should work well with Verified Sdk
|
|
196
|
+
|
|
197
|
+
# How to resolve Vite error(s) with Verified Sdk integration
|
|
198
|
+
|
|
199
|
+
Step 1: install @esbuild-plugins/node-modules-polyfill and rollup-plugin-polyfill-node
|
|
200
|
+
with npm: `npm i @esbuild-plugins/node-modules-polyfill rollup-plugin-polyfill-node`
|
|
201
|
+
with yarn: `yarn add @esbuild-plugins/node-modules-polyfill rollup-plugin-polyfill-node`
|
|
202
|
+
|
|
203
|
+
Step 2: Install needed dependencies
|
|
204
|
+
with npm:
|
|
205
|
+
`npm install --save-dev crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process`
|
|
206
|
+
with yarn:
|
|
207
|
+
`yarn add crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process`
|
|
208
|
+
|
|
209
|
+
Step 3: update vite.config.js file
|
|
210
|
+
From the root folder of your project update 'vite.config.js' to resolve missing dependencies
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
|
|
214
|
+
import nodePolyfills from "rollup-plugin-polyfill-node";
|
|
215
|
+
|
|
216
|
+
// https://vitejs.dev/config/
|
|
217
|
+
export default defineConfig({
|
|
218
|
+
build: {
|
|
219
|
+
target: ["es2020"], //optional can be customised
|
|
220
|
+
rollupOptions: {
|
|
221
|
+
plugins: [nodePolyfills()],
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
resolve: {
|
|
225
|
+
alias: {
|
|
226
|
+
process: "process/browser",
|
|
227
|
+
stream: "stream-browserify",
|
|
228
|
+
zlib: "browserify-zlib",
|
|
229
|
+
util: "util/",
|
|
230
|
+
path: "path-browserify",
|
|
231
|
+
"@": resolve(__dirname, "./src"), //optional
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
optimizeDeps: {
|
|
235
|
+
esbuildOptions: {
|
|
236
|
+
// Node.js global to browser globalThis
|
|
237
|
+
define: {
|
|
238
|
+
global: "globalThis",
|
|
239
|
+
},
|
|
240
|
+
supported: {
|
|
241
|
+
bigint: true, //optional
|
|
242
|
+
},
|
|
243
|
+
// Enable esbuild polyfill plugins
|
|
244
|
+
plugins: [
|
|
245
|
+
NodeGlobalsPolyfillPlugin({
|
|
246
|
+
buffer: true,
|
|
247
|
+
protocolImports: true,
|
|
248
|
+
}),
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
This 'vite.config.js' code snippet is telling webpack how to resolve the missing dependencies that are needed to support web3, ethers libraries and wallet providers in the browser/server side.
|
|
257
|
+
|
|
258
|
+
The polyfill node core module error should be fixed any missing NodeJS polyfills should be included in your app, and your app should work well with Verified Sdk.
|
|
259
|
+
|
|
120
260
|
# Verified Sdk also provides ERC 4337-compliant solution and enable account abstraction using Biconomy Smart Accounts.
|
|
121
261
|
|
|
122
262
|
Verified Sdk follows ERC 4337 standard and implement pseudo-transaction object(userOperation) to enable transaction sponsorship allowing smart contract creators to sponsor some set of transactions on smart contract for users when certain functions are called and allow multiple transaction to be called in batch
|
package/dist/contract/index.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
2
|
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
4
|
exports.VerifiedContract = exports.DATATYPES = void 0;
|
|
8
|
-
const dotenv_1 = require("dotenv");
|
|
9
|
-
dotenv_1.config({ path: "../../.env" });
|
|
10
5
|
const ethers_1 = require("ethers");
|
|
11
|
-
const web3_1 = __importDefault(require("web3"));
|
|
12
6
|
const account_1 = require("@biconomy/account");
|
|
13
7
|
const modules_1 = require("@biconomy/modules");
|
|
14
8
|
const bundler_1 = require("@biconomy/bundler");
|
|
@@ -185,7 +179,7 @@ class VerifiedContract {
|
|
|
185
179
|
async createSmartAccount(chainId) {
|
|
186
180
|
//create bundler instance
|
|
187
181
|
const bundler = new bundler_1.Bundler({
|
|
188
|
-
bundlerUrl: `${constants_1.PaymasterConstants.BUNDLER_URL_FIRST_SECTION}/${chainId}/${constants_1.PaymasterConstants
|
|
182
|
+
bundlerUrl: `${constants_1.PaymasterConstants.BUNDLER_URL_FIRST_SECTION}/${chainId}/${constants_1.PaymasterConstants[`${chainId}_URL_SECOND_SECTION`]}`,
|
|
189
183
|
chainId: chainId,
|
|
190
184
|
entryPointAddress: account_1.DEFAULT_ENTRYPOINT_ADDRESS,
|
|
191
185
|
});
|
|
@@ -243,7 +237,7 @@ class VerifiedContract {
|
|
|
243
237
|
}
|
|
244
238
|
}
|
|
245
239
|
/** Constructs and call function as userop for biconomy gassless(sponsored/erc20 mode) */
|
|
246
|
-
async callFunctionAsUserOp(smartAccount, userOp) {
|
|
240
|
+
async callFunctionAsUserOp(smartAccount, userOp, functionName, ...args) {
|
|
247
241
|
//send userops transaction and construct transaction response
|
|
248
242
|
let res = {};
|
|
249
243
|
try {
|
|
@@ -261,23 +255,27 @@ class VerifiedContract {
|
|
|
261
255
|
else {
|
|
262
256
|
const logs = transactionDetails.receipt.logs;
|
|
263
257
|
let reason = "";
|
|
264
|
-
const provider = this.contract.provider;
|
|
265
258
|
logs.map((log) => {
|
|
266
259
|
if (log.topics.includes(constants_1.PaymasterConstants.BICONOMY_REVERT_TOPIC)) {
|
|
267
|
-
|
|
268
|
-
|
|
260
|
+
try {
|
|
261
|
+
reason = ethers_1.utils.formatBytes32String(log.data);
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
reason = reason;
|
|
265
|
+
}
|
|
269
266
|
}
|
|
270
267
|
});
|
|
271
268
|
throw Error(`execution reverted: ${reason}`);
|
|
272
269
|
}
|
|
273
270
|
}
|
|
274
271
|
catch (err) {
|
|
275
|
-
console.
|
|
276
|
-
|
|
277
|
-
res.
|
|
278
|
-
res.
|
|
279
|
-
res.
|
|
280
|
-
|
|
272
|
+
console.error("gasless transaction failed with error: ", err);
|
|
273
|
+
console.log("will use ethers....");
|
|
274
|
+
// res.status = STATUS.ERROR;
|
|
275
|
+
// res.reason = err.reason;
|
|
276
|
+
// res.message = err.message;
|
|
277
|
+
// res.code = err.code;
|
|
278
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
281
279
|
}
|
|
282
280
|
}
|
|
283
281
|
async callContract(functionName, ...args) {
|
|
@@ -342,7 +340,7 @@ class VerifiedContract {
|
|
|
342
340
|
paymasterAndDataResponse.preVerificationGas;
|
|
343
341
|
}
|
|
344
342
|
}
|
|
345
|
-
return await this.callFunctionAsUserOp(smartAccount, partialUserOp);
|
|
343
|
+
return await this.callFunctionAsUserOp(smartAccount, partialUserOp, functionName, ...args);
|
|
346
344
|
}
|
|
347
345
|
catch (err) {
|
|
348
346
|
console.log("sponsored failed will try erc20");
|
|
@@ -383,7 +381,7 @@ class VerifiedContract {
|
|
|
383
381
|
const _paymasterAndDataWithLimits = await biconomyPaymaster.getPaymasterAndData(finalUserOp, paymasterServiceData);
|
|
384
382
|
finalUserOp.paymasterAndData =
|
|
385
383
|
_paymasterAndDataWithLimits.paymasterAndData;
|
|
386
|
-
return await this.callFunctionAsUserOp(smartAccount, finalUserOp);
|
|
384
|
+
return await this.callFunctionAsUserOp(smartAccount, finalUserOp, functionName, ...args);
|
|
387
385
|
}
|
|
388
386
|
catch (_err) {
|
|
389
387
|
//if erc20 mode didn't work use ethers.js
|
package/dist/utils/constants.js
CHANGED
|
@@ -4,10 +4,12 @@ exports.PaymasterConstants = void 0;
|
|
|
4
4
|
//Todo: add more network paymaster details for gasless
|
|
5
5
|
exports.PaymasterConstants = {
|
|
6
6
|
BUNDLER_URL_FIRST_SECTION: "https://bundler.biconomy.io/api/v2",
|
|
7
|
-
BUNDLER_URL_SECTION_SECTION: "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
|
|
8
7
|
GENERAL_PAYMASTER_URL: "https://paymaster.biconomy.io/api/v1",
|
|
9
8
|
BICONOMY_REVERT_TOPIC: "0x1c4fada7374c0a9ee8841fc38afe82932dc0f8e69012e927f061a8bae611a201",
|
|
10
9
|
"11155111_PAYMASTER_API_KEY": "BuFP2-5w-.5b3daf3a-d044-4dda-819c-4c4d8431df88",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
10
|
+
"11155111_URL_SECOND_SECTION": "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
|
|
11
|
+
// "137_PAYMASTER_API_KEY": "lDHvYk50N.30a2522e-0a9d-444b-b949-19194c1f237a",
|
|
12
|
+
// "137_URL_SECOND_SECTION": "dewj2189.wh1289hU-7E49-45ic-af80-JkuxGCYRV",
|
|
13
|
+
"80001_PAYMASTER_API_KEY": "3B83DXSwj.3b20bc68-6e09-4bf2-bff5-5a0d11989389",
|
|
14
|
+
"80001_URL_SECOND_SECTION": "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44"
|
|
13
15
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verified-network/verified-sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"description": "An SDK to develop applications on the Verified Network",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,12 +38,10 @@
|
|
|
38
38
|
"@biconomy/modules": "^3.1.1",
|
|
39
39
|
"@biconomy/paymaster": "^3.1.1",
|
|
40
40
|
"ethereumjs-tx": "^2.1.2",
|
|
41
|
-
"ethers": "^5.7.2"
|
|
42
|
-
"web3": "1.10.2"
|
|
41
|
+
"ethers": "^5.7.2"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@types/mocha": "^10.0.6",
|
|
46
|
-
"dotenv": "^10.0.0",
|
|
47
45
|
"mocha": "^10.2.0",
|
|
48
46
|
"ts-node": "^10.9.1",
|
|
49
47
|
"typescript": "^4.3.4"
|