- 需要启动本地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
eth_getTransactionByHash
eth_call
Contract call: SimpleStorage
From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
To: 0x5fbdb2315678afecb367f032d93f642f64180aa3
eth_blockNumber
eth_feeHistory
eth_sendTransaction
Contract call: SimpleStorage
Transaction: 0x6c18d4f86e31d8b6ec7f1dd48c7e0b212f6b2a839deba625459f98a197ffb32e
From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
To: 0x5fbdb2315678afecb367f032d93f642f64180aa3
Value: 0 ETH
Gas used: 43724 of 30000000
Block
eth_getTransactionByHash
eth_call
Contract call: SimpleStorage
From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
To: 0x5fbdb2315678afecb367f032d93f642f64180aa3