Skip to content

Commit 3c57aaa

Browse files
authored
Merge pull request #175 from saiakhil2012/akhil/add-vmbc-ethers-samples
Add VMBC Ethers related Sample Smart Contracts and DApps
2 parents 3cfbada + 5bd4218 commit 3c57aaa

File tree

14 files changed

+33547
-0
lines changed

14 files changed

+33547
-0
lines changed

vmbc-ethers-samples/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
## VMBC Ethers Sample DApps
2+
3+
### Table of Contents
4+
1. [Overview](#overview)
5+
2. [Prerequisites](#prerequisites)
6+
3. [Deploying Contract using Hardhat](#deploying-contract-using-hardhat)
7+
4. [Sample 1 - Get Greeting](#sample-1---get-greeting)
8+
5. [Sample 2 - Set Greeting](#sample-2---set-greeting)
9+
6. [Sample 3 - Data Copy](#sample-3---data-copy)
10+
7. [Sample 4 - Batching](#sample-4---batching)
11+
12+
### Overview
13+
Samples for using VMBC Ethers
14+
15+
### Prerequisites
16+
* Deploy VMware Blockchain
17+
* Install npm packages
18+
```sh
19+
# For hardhat related config
20+
npm install
21+
cd sample-dapps
22+
# For sample dapps
23+
npm install
24+
```
25+
26+
### Deploying Contract using Hardhat
27+
Following command uses `vmbc` network from inside the file `hardhat.config.js`
28+
```sh
29+
npx hardhat run --network vmbc scripts/deploy.js
30+
```
31+
Note: Make a note of Contract Address of Greetings Smart Contract from the output of above command
32+
33+
---
34+
35+
### Sample 1 - Get Greeting
36+
#### Overview
37+
* This sample depicts way to use view functions of deployed smart contracts
38+
#### Setup
39+
* Update the `CONTRACT_ADDRESS` to the contract address received from Deploying usin Hardhat step
40+
#### Executing
41+
```sh
42+
node 1_get_greetings.js
43+
```
44+
45+
---
46+
47+
### Sample 2 - Set Greeting
48+
#### Overview
49+
* This sample depicts way to call any write based functions of deployed smart contracts
50+
#### Setup
51+
* Update the `CONTRACT_ADDRESS` to the contract address received from Deploying usin Hardhat step
52+
* Update the `PRIVATE_KEY_ACC` to the private key of an account
53+
#### Executing
54+
```sh
55+
node 2_set_greetings.js
56+
```
57+
58+
---
59+
60+
### Sample 3 - Data Copy
61+
#### Overview
62+
* This sample depicts following aspects,
63+
* Compiling a Smart Contracts in JavaScript using `solc`
64+
* Deploying the Smart Contract
65+
* Interacting with programatically deployed Smart Contracts
66+
#### Setup
67+
* Update the `PRIVATE_KEY_ACC` to the private key of an account
68+
#### Executing
69+
```sh
70+
node 3_data_copy.js
71+
```
72+
73+
---
74+
75+
### Sample 4 - Batching
76+
#### Overview
77+
* This sample depicts following aspects,
78+
* Batching of multiple read based calls
79+
* Batching of multiple write based transactions
80+
#### Setup
81+
* Update `ACCOUNT_1`, `ACCOUNT_2`, `ACCOUNT_3` and `ACCOUNT_4` to the account addresses for 4 accounts
82+
* Update the corresponding `PRIVATE_KEY_ACC_1` and `PRIVATE_KEY_ACC_3` to the private key of those two accounts
83+
#### Executing
84+
```sh
85+
node 4_batching.js
86+
```
87+
88+
---
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.4.22 <0.9.0;
3+
contract DataCopy{
4+
5+
bytes public memoryStored;
6+
7+
function callDatacopy(bytes memory data) public returns (bytes memory) {
8+
memoryStored = data;
9+
return memoryStored;
10+
}
11+
12+
function getMemoryStored() public view returns (bytes memory) {
13+
return memoryStored;
14+
}
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.4.22 <0.9.0;
3+
4+
contract Greetings {
5+
string greeting = "Default-Greeting-From-Solidity";
6+
uint16 count = 0;
7+
8+
function setGreeting(string memory _newGreeting) public {
9+
emit NewGreetingEvent(msg.sender, greeting, _newGreeting);
10+
greeting = _newGreeting;
11+
++count;
12+
}
13+
14+
// update text
15+
function getGreeting() public view returns (string memory) {
16+
return greeting;
17+
}
18+
19+
event NewGreetingEvent(address _sender, string _oldGreeting, string _newGreeting);
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.4.22 <0.9.0;
3+
4+
contract Migrations {
5+
address public owner = msg.sender;
6+
uint public last_completed_migration;
7+
8+
modifier restricted() {
9+
require(
10+
msg.sender == owner,
11+
"This function is restricted to the contract's owner"
12+
);
13+
_;
14+
}
15+
16+
function setCompleted(uint completed) public restricted {
17+
last_completed_migration = completed;
18+
}
19+
}

vmbc-ethers-samples/hardhat.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require("@nomiclabs/hardhat-waffle");
2+
module.exports = {
3+
defaultNetwork: "vmbc",
4+
networks: {
5+
vmbc: {
6+
url: "http://127.0.0.1:8545"
7+
}
8+
},
9+
solidity: {
10+
version: "0.8.9",
11+
settings: {
12+
optimizer: {
13+
enabled: true,
14+
runs: 200
15+
}
16+
}
17+
},
18+
paths: {
19+
sources: "./contracts",
20+
},
21+
mocha: {
22+
timeout: 40000
23+
}
24+
}

0 commit comments

Comments
 (0)