-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from saiakhil2012/akhil/add-vmbc-ethers-samples
Add VMBC Ethers related Sample Smart Contracts and DApps
- Loading branch information
Showing
14 changed files
with
33,547 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.