Skip to content

Commit

Permalink
Merge pull request #175 from saiakhil2012/akhil/add-vmbc-ethers-samples
Browse files Browse the repository at this point in the history
Add VMBC Ethers related Sample Smart Contracts and DApps
  • Loading branch information
saiakhil2012 authored Oct 5, 2022
2 parents 3cfbada + 5bd4218 commit 3c57aaa
Show file tree
Hide file tree
Showing 14 changed files with 33,547 additions and 0 deletions.
88 changes: 88 additions & 0 deletions vmbc-ethers-samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
## VMBC Ethers Sample DApps

### Table of Contents
1. [Overview](#overview)
2. [Prerequisites](#prerequisites)
3. [Deploying Contract using Hardhat](#deploying-contract-using-hardhat)
4. [Sample 1 - Get Greeting](#sample-1---get-greeting)
5. [Sample 2 - Set Greeting](#sample-2---set-greeting)
6. [Sample 3 - Data Copy](#sample-3---data-copy)
7. [Sample 4 - Batching](#sample-4---batching)

### Overview
Samples for using VMBC Ethers

### Prerequisites
* Deploy VMware Blockchain
* Install npm packages
```sh
# For hardhat related config
npm install
cd sample-dapps
# For sample dapps
npm install
```

### Deploying Contract using Hardhat
Following command uses `vmbc` network from inside the file `hardhat.config.js`
```sh
npx hardhat run --network vmbc scripts/deploy.js
```
Note: Make a note of Contract Address of Greetings Smart Contract from the output of above command

---

### Sample 1 - Get Greeting
#### Overview
* This sample depicts way to use view functions of deployed smart contracts
#### Setup
* Update the `CONTRACT_ADDRESS` to the contract address received from Deploying usin Hardhat step
#### Executing
```sh
node 1_get_greetings.js
```

---

### Sample 2 - Set Greeting
#### Overview
* This sample depicts way to call any write based functions of deployed smart contracts
#### Setup
* Update the `CONTRACT_ADDRESS` to the contract address received from Deploying usin Hardhat step
* Update the `PRIVATE_KEY_ACC` to the private key of an account
#### Executing
```sh
node 2_set_greetings.js
```

---

### Sample 3 - Data Copy
#### Overview
* This sample depicts following aspects,
* Compiling a Smart Contracts in JavaScript using `solc`
* Deploying the Smart Contract
* Interacting with programatically deployed Smart Contracts
#### Setup
* Update the `PRIVATE_KEY_ACC` to the private key of an account
#### Executing
```sh
node 3_data_copy.js
```

---

### Sample 4 - Batching
#### Overview
* This sample depicts following aspects,
* Batching of multiple read based calls
* Batching of multiple write based transactions
#### Setup
* Update `ACCOUNT_1`, `ACCOUNT_2`, `ACCOUNT_3` and `ACCOUNT_4` to the account addresses for 4 accounts
* Update the corresponding `PRIVATE_KEY_ACC_1` and `PRIVATE_KEY_ACC_3` to the private key of those two accounts
#### Executing
```sh
node 4_batching.js
```

---
15 changes: 15 additions & 0 deletions vmbc-ethers-samples/contracts/DataCopy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
contract DataCopy{

bytes public memoryStored;

function callDatacopy(bytes memory data) public returns (bytes memory) {
memoryStored = data;
return memoryStored;
}

function getMemoryStored() public view returns (bytes memory) {
return memoryStored;
}
}
20 changes: 20 additions & 0 deletions vmbc-ethers-samples/contracts/Greetings.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Greetings {
string greeting = "Default-Greeting-From-Solidity";
uint16 count = 0;

function setGreeting(string memory _newGreeting) public {
emit NewGreetingEvent(msg.sender, greeting, _newGreeting);
greeting = _newGreeting;
++count;
}

// update text
function getGreeting() public view returns (string memory) {
return greeting;
}

event NewGreetingEvent(address _sender, string _oldGreeting, string _newGreeting);
}
19 changes: 19 additions & 0 deletions vmbc-ethers-samples/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Migrations {
address public owner = msg.sender;
uint public last_completed_migration;

modifier restricted() {
require(
msg.sender == owner,
"This function is restricted to the contract's owner"
);
_;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
}
24 changes: 24 additions & 0 deletions vmbc-ethers-samples/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require("@nomiclabs/hardhat-waffle");
module.exports = {
defaultNetwork: "vmbc",
networks: {
vmbc: {
url: "http://127.0.0.1:8545"
}
},
solidity: {
version: "0.8.9",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
paths: {
sources: "./contracts",
},
mocha: {
timeout: 40000
}
}
Loading

0 comments on commit 3c57aaa

Please sign in to comment.