-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmutableFunctionCall.ts
More file actions
54 lines (44 loc) · 1.59 KB
/
mutableFunctionCall.ts
File metadata and controls
54 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { ethers } from "ethers";
import { ExtensionContext } from "vscode";
import { logger } from "../../lib";
import { EstimateGas, useContractType } from "../../types";
import { getGasEstimates } from "../functions";
import {
getConfiguration,
getSelectedNetConf,
getSignedContract,
} from "../networks";
export const MutableFunctionCall = async (
context: ExtensionContext,
state: string,
params: any[],
useContract: useContractType
) => {
const MAX_FEE_PER_GAS = 100;
const { abiItemName, contractAddress, contractName } = useContract;
const contract = await getSignedContract(context, contractAddress);
let gasCondition = (await context.workspaceState.get("gas")) as string;
const gasEstimate: EstimateGas | undefined = await getGasEstimates(
gasCondition,
context
);
const maxFeePerGas =
gasEstimate !== undefined ? gasEstimate.maxFeePerGas : MAX_FEE_PER_GAS;
const settingsGasLimit = (await getConfiguration().get("gasLimit")) as number;
const value =
state === "payable" ? await context.workspaceState.get("payableValue") : 0;
const result = await contract[abiItemName as string](...params, {
value: value,
gasPrice: ethers.utils.parseUnits(maxFeePerGas.toString(), "gwei"),
gasLimit: settingsGasLimit,
});
logger.success("Waiting for confirmation...");
await result.wait();
logger.success("Transaction confirmed!");
logger.success(`Calling ${contractName} : ${abiItemName} --> Success!`);
logger.success(
`You can see detail of this transaction here. ${
getSelectedNetConf(context).blockScanner
}/tx/${result.hash}`
);
};