Skip to content

Commit

Permalink
Hardhat relay compatibility (#334)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
natanasow committed Jul 14, 2022
1 parent 73d8244 commit 637d3af
Show file tree
Hide file tree
Showing 13 changed files with 34,632 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/hardhat-example/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OPERATOR_PRIVATE_KEY=
RECEIVER_PRIVATE_KEY=
RELAY_ENDPOINT='http://localhost:7546'
10 changes: 10 additions & 0 deletions tools/hardhat-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types

#Hardhat files
cache
artifacts
24 changes: 24 additions & 0 deletions tools/hardhat-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Hardhat example

Simple scripts for basic operations like hbars transfer, balance fetching, and contract interactions (deployment and calls).

## Prerequisite
You must have running:
- JSON-RPC Relay

## Configuration

Create `.env` file based on `.env.example`
```
# Alias accounts keys
OPERATOR_PRIVATE_KEY=
RECEIVER_PRIVATE_KEY=
```

## Setup & Install

In the project directory:

1. Run `npm install`
2. Run `npx hardhat test`
18 changes: 18 additions & 0 deletions tools/hardhat-example/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

contract Greeter {
string private greeting;

constructor(string memory _greeting) {
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
greeting = _greeting;
}
}
57 changes: 57 additions & 0 deletions tools/hardhat-example/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*-
*
* Hedera JSON RPC Relay - Hardhat Example
*
* Copyright (C) 2022 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

require('dotenv').config();
require('@nomicfoundation/hardhat-toolbox');

task('show-balance', async () => {
const showBalance = require('./scripts/showBalance');
return showBalance();
});

task('transfer-hbars', async () => {
const transferHbars = require('./scripts/transferHbars');
return transferHbars();
});

task('deploy-contract', async () => {
const deployContract = require('./scripts/deployContract');
return deployContract();
});

task('contract-view-call', async (taskArgs) => {
const contractViewCall = require('./scripts/contractViewCall');
return contractViewCall(taskArgs.contractAddress);
});

task('contract-call', async (taskArgs) => {
const contractCall = require('./scripts/contractCall');
return contractCall(taskArgs.contractAddress, taskArgs.msg);
});

module.exports = {
solidity: '0.8.4',
defaultNetwork: 'relay',
networks: {
relay: {
url: process.env.RELAY_ENDPOINT
}
}
};
Loading

0 comments on commit 637d3af

Please sign in to comment.