-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (47 loc) · 1.23 KB
/
index.js
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
const firefly = require("firefly");
async function main() {
// Create a new contract interface
const contractInterface = {
name: "MyContract",
version: 1,
network: "ethereum",
connector: "hyperledger",
functions: [
{
name: "addOwner",
inputs: [
{
name: "owner",
type: "string",
},
],
outputs: [],
},
],
events: [
{
name: "OwnerAdded",
inputs: [
{
name: "owner",
type: "string",
},
],
},
],
};
// Broadcast the contract interface to the network
const response = await firefly.broadcastContractInterface(contractInterface);
console.log("Contract interface broadcasted successfully!", response);
// Create an HTTP API for the contract
const api = await firefly.createApi(contractInterface);
// Add the owner to the contract
const response2 = await api.addOwner("my-owner");
console.log("Owner added successfully!", response2);
// Check that the owner was added successfully
const event = await firefly.waitForEvent("OwnerAdded", {
owner: "my-owner",
});
console.log("Owner added successfully!");
}
main().catch(console.error);