0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Hello, hardhat! につまずいた

0
Last updated at Posted at 2022-06-23

次のページの案内に沿って、サンプルプロジェクトを実行し、localhost にデプロイしたときにつまづいた。

$ npx hardhat node
$ npx hardhat run --network localhost scripts/sample-scripts.js

上記を実行後、node を立ち上げて、以下のように greeter.greet() をしたら、CALL_EXCEPTION が出た。

> const hre = require("hardhat");
> address = "0x5FbDB2315678afecb367f032d93F642f64180aa3"
'0x5FbDB2315678afecb367f032d93F642f64180aa3'
> const contract = await hre.ethers.getContractAt("Greeter", address);
> await contract.greet()
Uncaught:
Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="greet()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.4)
    at Logger.makeError (/Users/ytakashina/workspace/achievement-maker/node_modules/@ethersproject/logger/lib/index.js:233:21)
    at Logger.throwError (/Users/ytakashina/workspace/achievement-maker/node_modules/@ethersproject/logger/lib/index.js:242:20)
    at Interface.decodeFunctionResult (/Users/ytakashina/workspace/achievement-maker/node_modules/@ethersproject/abi/lib/interface.js:388:23)
    at Contract.<anonymous> (/Users/ytakashina/workspace/achievement-maker/node_modules/@ethersproject/contracts/lib/index.js:395:56)
    at step (/Users/ytakashina/workspace/achievement-maker/node_modules/@ethersproject/contracts/lib/index.js:48:23) {
  reason: null,
  code: 'CALL_EXCEPTION',
  method: 'greet()',
  data: '0x',
  errorArgs: null,
  errorName: null,
  errorSignature: null,
  address: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
  args: [],
  transaction: {
    data: '0xcfae3217',
    to: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
    from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    gasLimit: BigNumber { value: "29021272" }
  }
}

原因を調査してみたところ、ちゃんとアドレスが指定できていなかったり、接続先のネットワークが間違っていると、このエラーが出るらしい。

普通に node を立ち上げるのではなく、hardhat console を使って接続先のネットワークを指定しなければいけなかった。

$ npx hardhat console --network localhost

(多分 node で立ち上げた上で localhost 繋ぐ方法もあるだろうけど、割愛。)

無事、Hello, Hardhat! できました :blush:

> await contract.greet()
'Hello, Hardhat!'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?