-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitialize.tsx
54 lines (47 loc) · 1.36 KB
/
Initialize.tsx
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 { detectConcordiumProvider, SmartContractParameters } from "@concordium/browser-wallet-api-helpers";
import {
AccountTransactionType,
CcdAmount,
InitContractPayload,
ModuleReference,
} from "@concordium/web-sdk";
import { Button, Link } from "@mui/material";
import { Buffer } from "buffer/";
import { useState } from "react";
export default function Initialize() {
const [hash, setHash] = useState("");
const initialize = async () => {
const provider = await detectConcordiumProvider();
const account = await provider.connect();
if (!account) {
alert("Please connect");
}
var REACT_APP_CONTRACT_NAME="CIS2-Multi";
var REACT_APP_MODULE_REF="312f99d6406868e647359ea816e450eac0ecc4281c2665a24936e6793535c9f6";
const txnHash = await provider.sendTransaction(
account!,
AccountTransactionType.InitContract as any,
{
amount: new CcdAmount(BigInt(0)),
initName: REACT_APP_CONTRACT_NAME,
moduleRef: new ModuleReference(REACT_APP_MODULE_REF),
param: Buffer.alloc(0),
maxContractExecutionEnergy: BigInt(9999),
} as InitContractPayload
);
setHash(txnHash);
};
return hash ? (
<Link
href={`https://dashboard.testnet.concordium.com/lookup/${hash}`}
target="_blank"
>
View Transaction <br />
{hash}
</Link>
) : (
<Button fullWidth variant="outlined" onClick={initialize}>
Initialize Contract
</Button>
);
}