0xSpaceShard / starknet-hardhat-plugin

A plugin for integrating Starknet tools into Hardhat projects
https://0xspaceshard.github.io/starknet-hardhat-plugin/
MIT License
197 stars 36 forks source link

Issues connecting to local devnet #27

Closed jag-lotus closed 2 years ago

jag-lotus commented 2 years ago

Hi,

When trying to run mocha tests on a local devnet (i.e. http://localhost:5000), Hardhat cannot connect to the network

yarn run v1.22.10
$ hardhat test
Starknet plugin using the active environment.

  Account
    1) should deploy the Account contract

  0 passing (3s)
  1 failing

  1) Account
       should deploy the Account contract:
     HardhatPluginError: Could not deploy contract. Check the network url in config. Is it responsive?
      at StarknetContractFactory.<anonymous> (node_modules/@shardlabs/starknet-hardhat-plugin/src/types.ts:223:19)
      at Generator.next (<anonymous>)
      at fulfilled (node_modules/@shardlabs/starknet-hardhat-plugin/dist/types.js:24:58)

You can see my hardhat.config.ts file here

import "@shardlabs/starknet-hardhat-plugin";
import { HardhatUserConfig } from "hardhat/config";

const config: HardhatUserConfig = {
  cairo: {
    venv: 'active',
  },
  defaultNetwork: 'devnet',
  networks: {
    devnet: {
      url: 'http://localhost:5000',
    }
  },
  mocha: {
    starknetNetwork: 'devnet',
  }
};

export default config;

I tried using both nile node and starknet-devnet and both fail.

I really like the ability to use Hardhat for Cairo development as well and keep Cairo and Solidity in the same project. Fixing this issue would really help in a major Cairo/StarkNet integration.

Setup: macOS 12.0.1 python 3.8.9 cairo-lang 0.6.1

FabijanC commented 2 years ago

Thanks for reporting this issue. It's caused by the way localhost (used by starknet-devnet) is targeted on macOS when using your own virtual environment (which as I see is specified by venv: "active").

I know how to fix this, but until then, I think the temporary solution is to use the Docker version of the plugin (so instead of venv: "active", you should specify version: "0.6.1").

And also, it is expected that if starknet-devnet has an issue that nile will also have it, because internally, nile relies on starknet-devnet.

jag-lotus commented 2 years ago

I'll use this fix for now, it's working fine.

Thanks, I look forward to being able to use venv in the future

FabijanC commented 2 years ago

This has been fixed since plugin v0.3.6.

clacladev commented 2 years ago

I cannot connect to devnet.

Here my hardhat.config.ts:

const config: HardhatUserConfig = {
  starknet: {
    venv: "active",
    network: "devnet",
  },
  networks: {
    devnet: {
      url: "http://localhost:5000/"
    }
  },
};

When I run yarn hardhat test:

yarn run v1.22.17
$ /Users/claudio/Dev/web3/starknet-hardhat-example-alt/node_modules/.bin/hardhat test
Starknet plugin using the active environment.

  Starknet
Started deployment
    1) should work for a fresh deployment

  0 passing (746ms)
  1 failing

  1) Starknet
       should work for a fresh deployment:
     HardhatPluginError: Could not deploy contract. Check the network url in config. Is it responsive?
      at StarknetContractFactory.<anonymous> (node_modules/@shardlabs/starknet-hardhat-plugin/src/types.ts:259:19)
      at Generator.next (<anonymous>)
      at fulfilled (node_modules/@shardlabs/starknet-hardhat-plugin/dist/types.js:24:58)

An unexpected error occurred:

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at hash160 (/Users/claudio/Dev/web3/starknet-hardhat-example-alt/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:249:21)
    at HDKey.set (/Users/claudio/Dev/web3/starknet-hardhat-example-alt/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:50:24)
    at Function.HDKey.fromMasterSeed (/Users/claudio/Dev/web3/starknet-hardhat-example-alt/node_modules/ethereum-cryptography/vendor/hdkey-without-crypto.js:194:20)
    at deriveKeyFromMnemonicAndPath (/Users/claudio/Dev/web3/starknet-hardhat-example-alt/node_modules/hardhat/src/internal/util/keys-derivation.ts:21:27)
    at derivePrivateKeys (/Users/claudio/Dev/web3/starknet-hardhat-example-alt/node_modules/hardhat/src/internal/core/providers/util.ts:29:52)
    at normalizeHardhatNetworkAccountsConfig (/Users/claudio/Dev/web3/starknet-hardhat-example-alt/node_modules/hardhat/src/internal/core/providers/util.ts:56:10)
    at createProvider (/Users/claudio/Dev/web3/starknet-hardhat-example-alt/node_modules/hardhat/src/internal/core/providers/construction.ts:78:59)
    at /Users/claudio/Dev/web3/starknet-hardhat-example-alt/node_modules/hardhat/src/internal/core/runtime-environment.ts:80:28 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Any idea why?

FabijanC commented 2 years ago

@ccarnino Can you post this as a separate issue? Also, if you could provide your OS, your plugin and devnet version.

clacladev commented 2 years ago

I will do it now