hashgraph / hedera-local-node

Run your own local Hedera network for development purposes.
Apache License 2.0
52 stars 56 forks source link

Consistent experience with hardhat network configs #359

Closed mgarbs closed 11 months ago

mgarbs commented 1 year ago

Problem

I added the local network to the config in this hardhat project and its not working like I would expect. Here is a hardhat project deploying a proxy contract on testnet

TESTNET➜  hedera-smart-contract-starter git:(upgrade-ethers) ✗ npx hardhat run scripts/create-node.ts --network hederaTestnet       

Fetching Node contract...
Deploying Node contract with topic ID '0.0.1234'...
Node contract deployed to: 0x410f41Ee667d089A544039c8C6580DDC94cA3d61
Node contract initialized with topic ID: 0.0.1234

Here is the same deploy script with a local node network config:

LOCAL_NODE➜  hedera-smart-contract-starter git:(upgrade-ethers) ✗ npx hardhat run scripts/create-node.ts --network localNetwork 

Fetching Node contract...
Deploying Node contract with topic ID '0.0.1234'...
ProviderError: [Request ID: 689a2e5d-72a9-445a-a7db-bc3802237e05] Requested resource not found. address '0x02Ef1094e35b47c5622799eFEc6FBd7646013337'.
    at HttpProvider.request (/Users/michaelgarber/hedera-smart-contract-starter/node_modules/hardhat/src/internal/core/providers/http.ts:88:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async EthersProviderWrapper.send (/Users/michaelgarber/hedera-smart-contract-starter/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

Here is the network configs:

 networks: {
    hederaTestnet: {
      url: "https://testnet.hashio.io/api",
      chainId: 296,
      accounts: [process.env.ECDSA_PRIVATE_KEY || ''],
      gas: "auto",
      gasPrice: "auto",
      gasMultiplier: 3 
    },
    localNetwork: {
      url: "http://127.0.0.1:7546/",
      chainId: 298,
      accounts: ['0x8cc267332c6ee3a74b4890221a6be37a074ee0fbe4323f3765cc84dcf8b16ab0'], // Private key generated from 'hedera generate-accounts 1'
      gas: "auto",
      gasPrice: "auto",
      gasMultiplier: 3 
    }
  }

Solution

Alternatives

No response

mgarbs commented 1 year ago

Additionally, when I run hedera start after installing it into a hardhat project with npm install @hashgraph/hedera-local the local node says it started, but it never generates any accounts image

I tried doing a separate command hedera generate-accounts 2 in another terminal window and that will create accounts, but I can't use them to sign any of the transactions in my deploy scripts because it consistently gives me the same error I noted at the beginning of this issue

georgi-l95 commented 1 year ago

Not sure why it's not the correct format, but you can press 4 and you'll see the generated accounts. Additionally you can run hedera start -d, to run it in detached mode and see if that helps.

ProviderError: [Request ID: 689a2e5d-72a9-445a-a7db-bc3802237e05] Requested resource not found. address '0x02Ef1094e35b47c5622799eFEc6FBd7646013337'. -> This error means that this account does not exist.

Also the account 0x02Ef1094e35b47c5622799eFEc6FBd7646013337 from your local config is not from the generated predefined accounts, are you sure it's correct.

I've tried your steps and it's working as expected. Can you try again after reading this comment and let me know ?

mgarbs commented 1 year ago

That address that shows up in the error is not from any account that I am using in the hardhat config but it consistently throws with this address when I use one of the local node generated accounts. This is the local node private key I used in my config: 0x7f109a9e3b0d8ecfba9cc23a3614433ce0fa7ddcc80f2a8f10b222179a5a80d6

I tried again and got the same error. This time I ran it in detached mode and it did give me back the accounts like you indicated it would. For some background, this is all coming from me adding a local node config to this smart contract starter: https://github.com/hashgraph/hedera-smart-contract-starter/pull/11

This is where Im facing the issue

Testnet works fine, but using local node it is not->


➜  hedera-smart-contract-starter git:(upgrade-ethers) ✗ npx hardhat run scripts/create-node.ts --network local

Fetching TopicNode contract...
Deploying TopicNode contract with topic ID '0.0.1234'...
ProviderError: [Request ID: 4808f487-ec6b-471b-92a7-e0f810e21f97] Requested resource not found. address '0xe261e26aECcE52b3788Fac9625896FFbc6bb4424'.
    at HttpProvider.request (/Users/michaelgarber/hedera-smart-contract-starter/node_modules/hardhat/src/internal/core/providers/http.ts:88:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async EthersProviderWrapper.send (/Users/michaelgarber/hedera-smart-contract-starter/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

➜  hedera-smart-contract-starter git:(upgrade-ethers) ✗ npx hardhat run scripts/create-node.ts --network testnet

Fetching TopicNode contract...
Deploying TopicNode contract with topic ID '0.0.1234'...
TopicNode contract deployed to: 0x79Bdd7f4EfF612AdBb69dB8b91Dd4dD88cEC5874
TopicNode contract initialized with topic ID: 0.0.1234```
mgarbs commented 1 year ago

Update: I got it to work!! This was my issue... From these:

|-----------------------------------------------------------------------------------------|
|------------------------------| Accounts list (ECDSA keys) |-----------------------------|
|    id    |                            private key                            |  balance |
|-----------------------------------------------------------------------------------------|
| 0.0.1002 - 0x7f109a9e3b0d8ecfba9cc23a3614433ce0fa7ddcc80f2a8f10b222179a5a80d6 - 10000 ℏ |
| 0.0.1003 - 0x6ec1f2e7d126a74a1d2ff9e1c5d90b92378c725e506651ff8bb8616a5c724628 - 10000 ℏ |
| 0.0.1004 - 0xb4d7f7e82f61d81c95985771b8abf518f9328d019c36849d4214b5f995d13814 - 10000 ℏ |
| 0.0.1005 - 0x941536648ac10d5734973e94df413c17809d6cc5e24cd11e947e685acfbd12ae - 10000 ℏ |
| 0.0.1006 - 0x5829cf333ef66b6bdd34950f096cb24e06ef041c5f63e577b4f3362309125863 - 10000 ℏ |
| 0.0.1007 - 0x8fc4bffe2b40b2b7db7fd937736c4575a0925511d7a0a2dfc3274e8c17b41d20 - 10000 ℏ |
| 0.0.1008 - 0xb6c10e2baaeba1fa4a8b73644db4f28f4bf0912cceb6e8959f73bb423c33bd84 - 10000 ℏ |
| 0.0.1009 - 0xfe8875acb38f684b2025d5472445b8e4745705a9e7adc9b0485a05df790df700 - 10000 ℏ |
| 0.0.1010 - 0xbdc6e0a69f2921a78e9af930111334a41d3fab44653c8de0775572c526feea2d - 10000 ℏ |
| 0.0.1011 - 0x3e215c3d2a59626a669ed04ec1700f36c05c9b216e592f58bbfd3d8aa6ea25f9 - 10000 ℏ |
|-----------------------------------------------------------------------------------------|

|--------------------------------------------------------------------------------------------------------------------------------------|
|--------------------------------------------------------------------------------------------------------------------------------------|
|    id    |               public address               |                             private key                            | balance |
|--------------------------------------------------------------------------------------------------------------------------------------|
| 0.0.1012 - 0x67D8d32E9Bf1a9968a5ff53B87d777Aa8EBBEe69 - 0x105d050185ccb907fba04dd92d8de9e32c18305e097ab41dadda21489a211524 - 10000 ℏ |
| 0.0.1013 - 0x05FbA803Be258049A27B820088bab1cAD2058871 - 0x2e1d968b041d84dd120a5860cee60cd83f9374ef527ca86996317ada3d0d03e7 - 10000 ℏ |
| 0.0.1014 - 0x927E41Ff8307835A1C081e0d7fD250625F2D4D0E - 0x45a5a7108a18dd5013cf2d5857a28144beadc9c70b3bdbd914e38df4e804b8d8 - 10000 ℏ |
| 0.0.1015 - 0xc37f417fA09933335240FCA72DD257BFBdE9C275 - 0x6e9d61a325be3f6675cf8b7676c70e4a004d2308e3e182370a41f5653d52c6bd - 10000 ℏ |
| 0.0.1016 - 0xD927017F5a6a7A92458b81468Dc71FCE6115B325 - 0x0b58b1bd44469ac9f813b5aeaf6213ddaea26720f0b2f133d08b6f234130a64f - 10000 ℏ |
| 0.0.1017 - 0x5C41A21F14cFe9808cBEc1d91b55Ba75ed327Eb6 - 0x95eac372e0f0df3b43740fa780e62458b2d2cc32d6a440877f1cc2a9ad0c35cc - 10000 ℏ |
| 0.0.1018 - 0xcdaD5844f865F379beA057fb435AEfeF38361B68 - 0x6c6e6727b40c8d4b616ab0d26af357af09337299f09c66704146e14236972106 - 10000 ℏ |
| 0.0.1019 - 0x6e5D3858f53FC66727188690946631bDE0466B1A - 0x5072e7aa1b03f531b4731a32a021f6a5d20d5ddc4e55acbb71ae202fc6f3a26d - 10000 ℏ |
| 0.0.1020 - 0x29cbb51A44fd332c14180b4D471FBBc6654b1657 - 0x60fe891f13824a2c1da20fb6a14e28fa353421191069ba6b6d09dd6c29b90eff - 10000 ℏ |
| 0.0.1021 - 0x17b2B8c63Fa35402088640e426c6709A254c7fFb - 0xeae4e00ece872dd14fb6dc7a04f390563c7d69d16326f2a703ec8e0934060cc7 - 10000 ℏ |
|--------------------------------------------------------------------------------------------------------------------------------------|

When I used the first key 0x7f109a9e3b0d8ecfba9cc23a3614433ce0fa7ddcc80f2a8f10b222179a5a80d6 or any of the keys in the first 10 keys, the error throws.. But when I use any key from the second set (for example 0x105d050185ccb907fba04dd92d8de9e32c18305e097ab41dadda21489a211524) then it works as expected

georgi-l95 commented 11 months ago

Hey @mgarbs yes, you can use only aliased ECDSA keys with hardhat or all evm tools. This is known limitation and works as expected.