【Hardhat 控制台】

  • 需要启动本地Node才行
  • 然后在新建的终端窗口中运行yarn hardhat console --network localhost,则会进入到Hardhat控制台
> yarn hardhat console --network localhost
yarn run v1.22.19
..\node_modules\.bin\hardhat console --network localhost
Welcome to Node.js v18.17.1.      
Type ".help" for more information.
> const simpleStorageFactory = await ethers.getContractFactory("SimpleStorage")
undefined
> const simpleStorage = await simpleStorageFactory.deploy()
undefined
> await simpleStorage.retrieve()
0n
> await simpleStorage.store("55")
ContractTransactionResponse {      
  provider: HardhatEthersProvider {
    _hardhatProvider: LazyInitializationProviderAdapter {
      _providerFactory: [AsyncFunction (anonymous)],
      _emitter: [EventEmitter],
      _initializingPromise: [Promise],
      provider: [BackwardsCompatibilityProviderAdapter]
    },
    _networkName: 'localhost',
    _blockListeners: [],
    _transactionHashListeners: Map(0) {},
    _eventListeners: []
  },
  blockNumber: 2,
  blockHash: '0x4f1cf42b83b001e086364780235ac43a0a7f72df09653ee80fa0dcab5a05b978',
  index: undefined,
  hash: '0x6c18d4f86e31d8b6ec7f1dd48c7e0b212f6b2a839deba625459f98a197ffb32e',
  type: 2,
  to: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
  from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  nonce: 1,
  gasLimit: 30000000n,
  gasPrice: 769727956n,
  maxPriorityFeePerGas: 0n,
  maxFeePerGas: 974186944n,
  data: '0x6057361d0000000000000000000000000000000000000000000000000000000000000037',
  value: 0n,
  chainId: 31337n,
  signature: Signature { r: "0x993573b5df72b9ac16a7000bab664453133ea76b3746e113afbd5fe793132707", s: "0x7a34d20e102f4378833b81d7cdd14833efcfc0cc39527151220fe43f74c6f09e", yParity: 0, networkV: null },
  accessList: []
}
> await simpleStorage.retrieve()
55n
  • 可以在运行的本地节点窗口查看得到日志信息
eth_chainId
eth_accounts
hardhat_metadata (20)
eth_chainId
eth_accounts
hardhat_metadata (20)
eth_blockNumber
eth_getBlockByNumber
eth_feeHistory
eth_sendTransaction
  Contract deployment: SimpleStorage
  Contract address:    0x5fbdb2315678afecb367f032d93f642f64180aa3
  Transaction:         0x4513914f378ac34a126e911c7bc4812924d4b07cb2471f5b7e2468d5be68019b
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  Value:               0 ETH
  Gas used:            562691 of 30000000
  Block #1:            0x965c10aced40d34c20aa35b4cf31f5e16233388824189507808ea9952ce2b406

eth_getTransactionByHash
eth_call
  Contract call:       SimpleStorage#retrieve
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0x5fbdb2315678afecb367f032d93f642f64180aa3

eth_blockNumber
eth_feeHistory
eth_sendTransaction
  Contract call:       SimpleStorage#store
  Transaction:         0x6c18d4f86e31d8b6ec7f1dd48c7e0b212f6b2a839deba625459f98a197ffb32e
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0x5fbdb2315678afecb367f032d93f642f64180aa3
  Value:               0 ETH
  Gas used:            43724 of 30000000
  Block #2:            0x4f1cf42b83b001e086364780235ac43a0a7f72df09653ee80fa0dcab5a05b978

eth_getTransactionByHash
eth_call
  Contract call:       SimpleStorage#retrieve
  From:                0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
  To:                  0x5fbdb2315678afecb367f032d93f642f64180aa3
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值