我有一份ethers与之进行交易的合同:
const randomSVG = new ethers.Contract(RandomSVG.address, RandomSVGContract.interface, signer)
let tx = await randomSVG.create()
Run Code Online (Sandbox Code Playgroud)
我有一个与此交易有关的事件:
function create() public returns (bytes32 requestId) {
requestId = requestRandomness(keyHash, fee);
emit requestedRandomSVG(requestId);
}
Run Code Online (Sandbox Code Playgroud)
但是,我看不到交易收据中的日志。]( https://docs.ethers.io/v5/api/providers/types/#providers-TransactionReceipt )
// This returns undefined
console.log(tx.logs)
Run Code Online (Sandbox Code Playgroud) 我试图用参数验证我的合同,但收到此错误:
Error in plugin @nomiclabs/hardhat-etherscan: The contract verification failed.
Reason: Fail - Unable to verify
Run Code Online (Sandbox Code Playgroud)
我还导入Open Zeppelin合同ERC721Enumerable和Ownable.
这是我的NFTCollectible.sol
pragma solidity 0.8.10;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "hardhat/console.sol";
contract NFTCollectible is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.08 ether;
uint256 public maxSupply = 5000;
uint256 public maxMintAmount = 25;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol, …Run Code Online (Sandbox Code Playgroud) 我想创建一个包含功能的应付令牌transferAndCall(TokenReceiver to, uint256 amount, bytes4 selector)。通过调用该函数,您可以将代币转移到TokenReceiver智能合约地址,然后调用接收者,接收者又调用接收者onTransferReceived(address from,uint tokensPaid, bytes4 selector)中指定的函数。bytes4 selector
请注意,这与 ERC1363 类似/受到ERC1363的启发。
这是我的应收令牌的简化版本:
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MeowToken is ERC20 {
constructor() ERC20("MeowToken", "MEO") {
ERC20._mint(msg.sender, 10_000_000);
}
function transferAndCall(
TokenReceiver to,
uint256 amount,
bytes4 selector
) external {
ERC20.transfer(address(to), amount);
to.onTransferReceived(msg.sender, amount, selector);
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个令牌接收器:
contract TokenReceiver {
address acceptedToken;
event PurchaseMade(address from, uint tokensPaid);
modifier acceptedTokenOnly () {
require(msg.sender == address(acceptedToken), "Should be called only via the …Run Code Online (Sandbox Code Playgroud) 我是使用 Hardhat 部署智能合约的新手,正在遵循https://dev.to/dabit3/the-complete-guide-to-full-stack-ethereum-development-3j13上的教程。但是,运行后npx hardhat run scripts/deploy.js --network localhost,我收到以下错误。关于如何解决连接问题有什么想法吗?
HardhatError: HH108: Cannot connect to the network localhost.
Please make sure your node is running, and check your internet connection and networks config
at HttpProvider._fetchJsonRpcResponse (/Users/cuneydtasoglu/Desktop/hardhat_list/blockchain/node_modules/hardhat/src/internal/core/providers/http.ts:176:15)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
at HttpProvider.request (/Users/cuneydtasoglu/Desktop/hardhat_list/blockchain/node_modules/hardhat/src/internal/core/providers/http.ts:55:29)
at GanacheGasMultiplierProvider._isGanache (/Users/cuneydtasoglu/Desktop/hardhat_list/blockchain/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:302:30)
at GanacheGasMultiplierProvider.request (/Users/cuneydtasoglu/Desktop/hardhat_list/blockchain/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:291:23)
at EthersProviderWrapper.send (/Users/cuneydtasoglu/Desktop/hardhat_list/blockchain/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
at Object.getSigners (/Users/cuneydtasoglu/Desktop/hardhat_list/blockchain/node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:23:20)
at getContractFactoryByAbiAndBytecode (/Users/cuneydtasoglu/Desktop/hardhat_list/blockchain/node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:250:21)
at main (/Users/cuneydtasoglu/Desktop/hardhat_list/blockchain/scripts/deploy.js:17:19)
Caused by: FetchError: request to http://127.0.0.1:8545/ failed, reason: connect ECONNREFUSED 127.0.0.1:8545
at ClientRequest.<anonymous> (/Users/cuneydtasoglu/Desktop/hardhat_list/blockchain/node_modules/node-fetch/lib/index.js:1461:11)
at ClientRequest.emit (node:events:376:20)
at Socket.socketErrorListener …Run Code Online (Sandbox Code Playgroud) 我不明白问题是什么。当我运行该应用程序时,我收到此错误:
Unhandled Runtime Error
Error: invalid address or ENS name (argument="name", value=5.050201689117535e+47, code=INVALID_ARGUMENT, version=contracts/5.5.0)
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
import {ethers} from 'ethers'
import {useEffect, useState} from 'react'
import axios from 'axios'
import Web3Modal from 'web3modal'
import { nftaddress, nftmarketaddress } from '../config'
import NFT from '../artifacts/contracts/NFT.sol/NFT.json'
import Market from '../artifacts/contracts/Market.sol/Market.json'
export default function Home() {
const [nfts, setNFts] = useState([])
const [loadingState, setLoadingState] = useState('not-loaded')
useEffect(()=> {
loadNFTs()
}, [])
async function loadNFTs() {
// what we want to load:
// ***provider, tokenContract, …Run Code Online (Sandbox Code Playgroud) 有人可以给我指出解释该功能的文档(官方或其他)吗ethers.getContractAt():
其原始上下文如下:
vrfCoordinator = await ethers.getContractAt('VRFCoordinatorMock', VRFCoordinatorMock.address, signer)
Run Code Online (Sandbox Code Playgroud)
完整的代码可以在这里找到... https://github.com/PatrickAlphaC/all-on-chain- generated-nft/blob/main/deploy/02_Deploy_RandomSVG.js
如果没有此类文档,我们将不胜感激。谢谢你!
我正在尝试使用 Hardhat 运行脚本来部署具有构造函数参数的合约。当我运行时,npx hardhat run scripts\deploy.js --network rinkeby我收到错误:
Error: missing argument: in Contract constructor (count=0, expectedCount=7, code=MISSING_ARGUMENT, version=contracts/5.5.0)
我尝试使用 --constructor-args 参数,但出现另一个错误:
Error HH305: Unrecognized param --constructor-args
我发现的对 constructor-args 的所有引用都表明它只能作为Hardhat verify 的一部分,而不是Hardhat run 的一部分,但如果是这种情况,我如何在部署时传递参数?
更新以包含部署脚本
// deploy.js
async function main() {
const [deployer] = await ethers.getSigners();
console.log('%c \n Deploying contracts with the account:', 'color:', deployer.address );
console.log('%c \n Account balance:', 'color:', (await deployer.getBalance()).toString() );
const Token = await ethers.getContractFactory("Test01");
const token = await Token.deploy();
console.log('%c …Run Code Online (Sandbox Code Playgroud) 我打算在Hardhat中开发我的智能合约,并在 RSK regtest 本地节点上测试它们。我找到了Truffle regtest 配置。
development: {
host: "127.0.0.1",
port: 4444,
network_id: "*"
},
Run Code Online (Sandbox Code Playgroud)
hardhat.config.js在 RSK regtest 上运行测试需要什么配置?
我正在尝试在 Goerli 上部署合约,但我不断收到错误Error HH100: Network goerli doesn't exist
这是我的hardhat.config.ts
require("dotenv").config();
import { task } from 'hardhat/config';
import '@nomiclabs/hardhat-waffle';
import '@typechain/hardhat'
import '@nomiclabs/hardhat-ethers';
import { HardhatUserConfig } from "hardhat/config";
const PrivateKey = "b427...";
const config: HardhatUserConfig = {
solidity: {
version: '0.8.0',
},
networks: {
goerli: {
chainId: 5,
url: "https://goerli.infura.io/v3/309820d3955640ec9cda472d998479ef",
accounts: [PrivateKey],
},
},
};
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task('accounts', 'Prints the list of …Run Code Online (Sandbox Code Playgroud) 当我想ethers从中导入时hardhat,会抛出我在标题中提到的错误,这里是完整版本
- error TS2305: Module '"hardhat"' has no exported member 'ethers'.
2 import { ethers } from "hardhat";
~~~~~~
Run Code Online (Sandbox Code Playgroud)
虽然我在之前的项目中以同样的方式使用它并且看到每个人都这样做
hardhat ×10
ethers.js ×5
solidity ×5
ethereum ×3
javascript ×2
rsk ×2
typescript ×2
config ×1
etherscan ×1
metamask ×1
nft ×1
openzeppelin ×1
reactjs ×1
truffle ×1
web3js ×1