@arcblock/erc721did-contract 0.3.17 → 0.3.19

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.
@@ -165,10 +165,13 @@ async function getGasPrice({ provider }) {
165
165
  }
166
166
 
167
167
  async function getTxData(params = {}, type = 'arcblock') {
168
- const { contract, fn, args, value } = params;
169
- const txData = contract.interface.encodeFunctionData(fn, args);
168
+ const { contract, fn, args, value, txData: _txData, chainId: _chainId, gasLimit: _gasLimit, to: _to } = params;
170
169
 
171
- const chainId = await getChainId({ contract });
170
+ // if txData is set, ignore fn and args
171
+ const txData = _txData || contract.interface.encodeFunctionData(fn, args);
172
+
173
+ // if txData is set, ignore contract
174
+ const chainId = _chainId || (await getChainId({ contract }));
172
175
 
173
176
  // const gasPrice = await getGasPrice({ provider: contract.provider });
174
177
  // const gasPriceAsGwei = Math.ceil(ethers.utils.formatUnits(gasPrice, 'gwei').toString());
@@ -179,13 +182,17 @@ async function getTxData(params = {}, type = 'arcblock') {
179
182
  }
180
183
  : {};
181
184
 
182
- const gasLimit = await contract.provider
183
- .estimateGas({
184
- to: contract.address,
185
- data: txData,
186
- ...extraEtherValueMap,
187
- })
188
- .then((res) => res.toString());
185
+ const to = _to || contract?.address || null;
186
+
187
+ const gasLimit =
188
+ _gasLimit ||
189
+ (await contract.provider
190
+ .estimateGas({
191
+ to,
192
+ data: txData,
193
+ ...extraEtherValueMap,
194
+ })
195
+ .then((res) => res.toString()));
189
196
 
190
197
  if (type === 'arcblock') {
191
198
  return toBase58(
@@ -193,10 +200,10 @@ async function getTxData(params = {}, type = 'arcblock') {
193
200
  JSON.stringify({
194
201
  network: chainId,
195
202
  tx: {
196
- to: contract.address,
203
+ to,
197
204
  value: '0',
198
- ...extraEtherValueMap,
199
205
  gasLimit,
206
+ ...extraEtherValueMap,
200
207
  data: txData,
201
208
  },
202
209
  }),
@@ -359,6 +366,11 @@ const getEvmChainList = () => {
359
366
  return defaultChainList;
360
367
  };
361
368
 
369
+ async function createContractFactory({ abi, bytecode, signer } = {}) {
370
+ const factory = new ethers.ContractFactory(abi, bytecode, signer);
371
+ return factory;
372
+ }
373
+
362
374
  module.exports.getContract = getContract;
363
375
  module.exports.getContractFactory = getContractFactory;
364
376
  module.exports.getTxData = getTxData;
@@ -375,3 +387,4 @@ module.exports.getEvmChainList = getEvmChainList;
375
387
  module.exports.setupContractEnv = setupContractEnv;
376
388
  module.exports.getChainIdByChainName = getChainIdByChainName;
377
389
  module.exports.ethers = ethers;
390
+ module.exports.createContractFactory = createContractFactory;
@@ -1184,10 +1184,13 @@ async function getGasPrice({ provider }) {
1184
1184
  }
1185
1185
 
1186
1186
  async function getTxData(params = {}, type = 'arcblock') {
1187
- const { contract, fn, args, value } = params;
1188
- const txData = contract.interface.encodeFunctionData(fn, args);
1187
+ const { contract, fn, args, value, txData: _txData, chainId: _chainId, gasLimit: _gasLimit, to: _to } = params;
1189
1188
 
1190
- const chainId = await getChainId({ contract });
1189
+ // if txData is set, ignore fn and args
1190
+ const txData = _txData || contract.interface.encodeFunctionData(fn, args);
1191
+
1192
+ // if txData is set, ignore contract
1193
+ const chainId = _chainId || (await getChainId({ contract }));
1191
1194
 
1192
1195
  // const gasPrice = await getGasPrice({ provider: contract.provider });
1193
1196
  // const gasPriceAsGwei = Math.ceil(ethers.utils.formatUnits(gasPrice, 'gwei').toString());
@@ -1198,13 +1201,17 @@ async function getTxData(params = {}, type = 'arcblock') {
1198
1201
  }
1199
1202
  : {};
1200
1203
 
1201
- const gasLimit = await contract.provider
1202
- .estimateGas({
1203
- to: contract.address,
1204
- data: txData,
1205
- ...extraEtherValueMap,
1206
- })
1207
- .then((res) => res.toString());
1204
+ const to = _to || contract?.address || null;
1205
+
1206
+ const gasLimit =
1207
+ _gasLimit ||
1208
+ (await contract.provider
1209
+ .estimateGas({
1210
+ to,
1211
+ data: txData,
1212
+ ...extraEtherValueMap,
1213
+ })
1214
+ .then((res) => res.toString()));
1208
1215
 
1209
1216
  if (type === 'arcblock') {
1210
1217
  return toBase58(
@@ -1212,10 +1219,10 @@ async function getTxData(params = {}, type = 'arcblock') {
1212
1219
  JSON.stringify({
1213
1220
  network: chainId,
1214
1221
  tx: {
1215
- to: contract.address,
1222
+ to,
1216
1223
  value: '0',
1217
- ...extraEtherValueMap,
1218
1224
  gasLimit,
1225
+ ...extraEtherValueMap,
1219
1226
  data: txData,
1220
1227
  },
1221
1228
  }),
@@ -1378,6 +1385,11 @@ const getEvmChainList = () => {
1378
1385
  return defaultChainList;
1379
1386
  };
1380
1387
 
1388
+ async function createContractFactory({ abi, bytecode, signer } = {}) {
1389
+ const factory = new ethers.ContractFactory(abi, bytecode, signer);
1390
+ return factory;
1391
+ }
1392
+
1381
1393
  var getContract_1 = contract$1.getContract = getContract;
1382
1394
  var getContractFactory_1 = contract$1.getContractFactory = getContractFactory;
1383
1395
  var getTxData_1 = contract$1.getTxData = getTxData;
@@ -1394,5 +1406,6 @@ var getEvmChainList_1 = contract$1.getEvmChainList = getEvmChainList;
1394
1406
  var setupContractEnv_1 = contract$1.setupContractEnv = setupContractEnv;
1395
1407
  var getChainIdByChainName_1 = contract$1.getChainIdByChainName = getChainIdByChainName;
1396
1408
  var ethers_1 = contract$1.ethers = ethers;
1409
+ var createContractFactory_1 = contract$1.createContractFactory = createContractFactory;
1397
1410
 
1398
- export { contract$1 as default, ethers_1 as ethers, getAddressExplorerUrl_1 as getAddressExplorerUrl, getBlockExplorerUrl_1 as getBlockExplorerUrl, getChainId_1 as getChainId, getChainIdByChainName_1 as getChainIdByChainName, getChainInfo_1 as getChainInfo, getCloneContractArgs_1 as getCloneContractArgs, getContract_1 as getContract, getContractFactory_1 as getContractFactory, getEvmChainList_1 as getEvmChainList, getGasPrice_1 as getGasPrice, getTxData_1 as getTxData, getTxExplorerUrl_1 as getTxExplorerUrl, onContractFilter_1 as onContractFilter, setupContractEnv_1 as setupContractEnv, waitForTxReceipt_1 as waitForTxReceipt };
1411
+ export { createContractFactory_1 as createContractFactory, contract$1 as default, ethers_1 as ethers, getAddressExplorerUrl_1 as getAddressExplorerUrl, getBlockExplorerUrl_1 as getBlockExplorerUrl, getChainId_1 as getChainId, getChainIdByChainName_1 as getChainIdByChainName, getChainInfo_1 as getChainInfo, getCloneContractArgs_1 as getCloneContractArgs, getContract_1 as getContract, getContractFactory_1 as getContractFactory, getEvmChainList_1 as getEvmChainList, getGasPrice_1 as getGasPrice, getTxData_1 as getTxData, getTxExplorerUrl_1 as getTxExplorerUrl, onContractFilter_1 as onContractFilter, setupContractEnv_1 as setupContractEnv, waitForTxReceipt_1 as waitForTxReceipt };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.17",
6
+ "version": "0.3.19",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": "./lib/esm",
@@ -38,7 +38,7 @@
38
38
  "@rollup/plugin-json": "^6.0.0",
39
39
  "@rollup/plugin-node-resolve": "^15.1.0",
40
40
  "@types/mocha": "^10.0.1",
41
- "@types/node": "^18.17.0",
41
+ "@types/node": "^18.17.1",
42
42
  "chai": "^4.3.7",
43
43
  "dotenv-flow": "^3.2.0",
44
44
  "envfile": "^6.18.0",