Skip to content

Commit 637d3af

Browse files
authored
Hardhat relay compatibility (#334)
* Add hardhat scripts for contract and user interactions Signed-off-by: nikolay <[email protected]> * Add readme Signed-off-by: nikolay <[email protected]> * Fix code smells Signed-off-by: nikolay <[email protected]> * Add relay endpoint url in .env Signed-off-by: nikolay <[email protected]> * Uncomment tests Signed-off-by: nikolay <[email protected]> * Add license headers Signed-off-by: nikolay <[email protected]>
1 parent 73d8244 commit 637d3af

File tree

13 files changed

+34632
-0
lines changed

13 files changed

+34632
-0
lines changed

tools/hardhat-example/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OPERATOR_PRIVATE_KEY=
2+
RECEIVER_PRIVATE_KEY=
3+
RELAY_ENDPOINT='http://localhost:7546'

tools/hardhat-example/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
.env
3+
coverage
4+
coverage.json
5+
typechain
6+
typechain-types
7+
8+
#Hardhat files
9+
cache
10+
artifacts

tools/hardhat-example/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Hardhat example
2+
3+
Simple scripts for basic operations like hbars transfer, balance fetching, and contract interactions (deployment and calls).
4+
5+
## Prerequisite
6+
You must have running:
7+
- JSON-RPC Relay
8+
9+
## Configuration
10+
11+
Create `.env` file based on `.env.example`
12+
```
13+
# Alias accounts keys
14+
OPERATOR_PRIVATE_KEY=
15+
RECEIVER_PRIVATE_KEY=
16+
17+
```
18+
19+
## Setup & Install
20+
21+
In the project directory:
22+
23+
1. Run `npm install`
24+
2. Run `npx hardhat test`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//SPDX-License-Identifier: Unlicense
2+
pragma solidity ^0.8.0;
3+
4+
contract Greeter {
5+
string private greeting;
6+
7+
constructor(string memory _greeting) {
8+
greeting = _greeting;
9+
}
10+
11+
function greet() public view returns (string memory) {
12+
return greeting;
13+
}
14+
15+
function setGreeting(string memory _greeting) public {
16+
greeting = _greeting;
17+
}
18+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*-
2+
*
3+
* Hedera JSON RPC Relay - Hardhat Example
4+
*
5+
* Copyright (C) 2022 Hedera Hashgraph, LLC
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
require('dotenv').config();
22+
require('@nomicfoundation/hardhat-toolbox');
23+
24+
task('show-balance', async () => {
25+
const showBalance = require('./scripts/showBalance');
26+
return showBalance();
27+
});
28+
29+
task('transfer-hbars', async () => {
30+
const transferHbars = require('./scripts/transferHbars');
31+
return transferHbars();
32+
});
33+
34+
task('deploy-contract', async () => {
35+
const deployContract = require('./scripts/deployContract');
36+
return deployContract();
37+
});
38+
39+
task('contract-view-call', async (taskArgs) => {
40+
const contractViewCall = require('./scripts/contractViewCall');
41+
return contractViewCall(taskArgs.contractAddress);
42+
});
43+
44+
task('contract-call', async (taskArgs) => {
45+
const contractCall = require('./scripts/contractCall');
46+
return contractCall(taskArgs.contractAddress, taskArgs.msg);
47+
});
48+
49+
module.exports = {
50+
solidity: '0.8.4',
51+
defaultNetwork: 'relay',
52+
networks: {
53+
relay: {
54+
url: process.env.RELAY_ENDPOINT
55+
}
56+
}
57+
};

0 commit comments

Comments
 (0)