Why Could not find artifacts for contract from any sources - ethereum

I am using windows 10 with truffle and ganache-cli. I have 2 contracts file to be deployed contain interfaces of other contracts defined within the contract:
Contracts:
ERC721Mintable.sol
Ownable
Pausable is Ownable
ERC165
ERC721 is Pausable, ERC165
ERC721Enumerable is ERC165, ERC721
ERC721MetaData is ERC721Enumerable, usingOraclize
CraveuERC721Token is ERC721MetaData
Verifier.sol
SolnSquareVerifier.sol
pragma solidity >=0.4.21 <0.6.0;
import "./ERC721Mintable.sol";
import "./Verifier.sol";
contract SolnSqaureVerifier is CraveuERC721Token {
SquareVerifier squareVerifier;
constructor(address verifierAddress) public {
squareVerifier = SquareVerifier(verifierAddress);
}
Here's my deploy_contracts.js:
const SquareVerifier = artifacts.require("Verifier");
const SolnSquareVerifier = artifacts.require("SolnSquareVerifier");
module.exports = function(deployer) {
deployer.deploy(SquareVerifier).then( () => {
return deployer.deploy(SolnSquareVerifier, SquareVerifier.address);
});
};
I am using truffle version 5.0.18
Error Produced: Error: Error: Could not find artifacts for
SolnSquareVerifier from any sources

There is a typo in your contract name SolnSqaureVerifier, it should be SolnSquareVerifier

Rename the .sol file in contract folder to any name that you want.
Then truffle migrate again.

Related

Unable to create contract clone on Hardhat. "Error: Transaction reverted: function call to a non-contract account"

I'm trying to create a clone using OpenZeppelin Clones library. However, it seems that hardhat is not able to recognize the created clone contracts address.
The same code works on Remix, so does this have something to with Hardhat? NOTE: I have tried using Ganache as well, however it reverts with the same error.
Here is my factory contract:
contract WhoopyFactory {
address immutable implementationContract;
address[] public allClones;
event NewClone(address indexed _instance);
mapping(address => address) public whoopyList;
constructor() {
implementationContract = address (new Whoopy());
}
function createClone(address _whoopyCreator) payable external returns(address) { address clone = Clones.clone(implementationContract); Whoopy(clone).initialize(_whoopyCreator);
emit NewClone(clone);
return clone;
}
And here is the test I am running:
describe("Whoopy + WhoopyFactory", function () {
it("Initialises contract correctly", async function () {
const provider = new ethers.providers.JsonRpcProvider("HTTP://127.0.0.1:7545")
const deployer = provider.getSigner(0);
const player = provider.getSigner(1);
Whoopy = await ethers.getContractFactory("Whoopy")
whoopy = await Whoopy.deploy()
await whoopy.deployed()
WhoopyFactory = await ethers.getContractFactory("WhoopyFactory")
wf = await WhoopyFactory.deploy()
await wf.deployed()
wf.connect(player)
const tx = await wf.createClone("0x70997970C51812dc3A010C7d01b50e0d17dc79C8")
console.log(tx)
const txReceipt = await tx.wait(1)
console.log(txReceipt)
This is the error which reverts:
Error: Transaction reverted: function call to a non-contract account
at Whoopy.initialize (contracts/Whoopy.sol:117)
at <UnrecognizedContract>.<unknown> (0x9f1ac54bef0dd2f6f3462ea0fa94fc62300d3a8e)
As I said before, this code works correctly on Remix. Hope someone can point me in the right direction. Thanks in advance!
From what I understood, you are deploying a smart contract on Ganache, you can use hardhat's own local chain, by doing yarn chain, or npx hardhat node, and change the port to 8545.
You can make it more simpler by replacing the following
const provider = new ethers.providers.JsonRpcProvider("HTTP://127.0.0.1:7545")
const deployer = provider.getSigner(0);
const player = provider.getSigner(1);
with
const accounts = await hre.ethers.getSigners();
const deployer = accounts[0];
const player = accounts[1];
and while deploying use npx hardhat test --network localhost

How to pass an Interface object in a constructor parameter?

I don't know how to deploy this contract whit HARDHAT because there is an Interface object in the constructor.
Please can someone explain to me how to initialize IUniswapV2Pair _pair
IUniswapV2Pair is a Uniswap Library written in Solidity.
const Unitest = await hre.ethers.getContractFactory("Unitest");
const unitest = await Unitest.deploy(int256 .....,
uint256 .... , IUniswapV2Pair(?????));
await unitest.deployed();
console.log("unitest deployed to:", unitest.address);
You get the address of Interface. This is in rinkeby: https://rinkeby.etherscan.io/address/0x6bcd5b1e919277afe06a3f6355265ff3cf7956a4#code
and then when you deploy the contract,
const Uniswap = await hre.ethers.getContractFactory("ContractName");
const contract = await NFTMarket.deploy("0x6BcD5b1E919277AFe06a3f6355265ff3Cf7956A4",period,startTime);

getting error when i deploy the NFT with ETH

I am new in NFT, i am trying to create test NFT, when i am trying to deploy that NFT, i am getting this error,insufficient funds for intrinsic transaction cost, even though in my account have 1 ETH balance here i have attached my whole code of it, can anyone please help me, how to resolve this issue ?
MyNFT.sol
//Contract based on [https://docs.openzeppelin.com/contracts/3.x/erc721](https://docs.openzeppelin.com/contracts/3.x/erc721)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/utils/Counters.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract MyNFT is ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("MyNFT", "NFT") {}
function mintNFT(address recipient, string memory tokenURI)
public onlyOwner
returns (uint256)
{
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, tokenURI);
return newItemId;
}
}
hardhat.config.js
/**
* #type import('hardhat/config').HardhatUserConfig
*/
require('dotenv').config();
require("#nomiclabs/hardhat-ethers");
const { API_URL, PRIVATE_KEY } = process.env;
//console.log(PRIVATE_KEY);
module.exports = {
solidity: "0.8.1",
defaultNetwork: "ropsten",
networks: {
hardhat: {},
ropsten: {
url: API_URL,
accounts: [`0x${PRIVATE_KEY}`]
}
},
}
deploy.js
async function main() {
const MyNFT = await ethers.getContractFactory("MyNFT")
// Start deployment, returning a promise that resolves to a contract object
const myNFT = await MyNFT.deploy()
await myNFT.deployed()
console.log("Contract deployed to address:", myNFT.address)
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
That error is clear. you do not have sufficient funds. This is how you are getting the account information:
const { API_URL, PRIVATE_KEY } = process.env;
I had an issue with webpack once destructuring process.env. Try this
// ASSUMING you pass correct private key here
const PRIVATE_KEY = process.env.PRIVATE_KEY;
console.log the private key.
If it does not get resolved, that means you are not passing the correct PRIVATE_KEY.

Deploy contract to local hardhat node with forked Kovan chain

I am trying to write tests for my contract on Kovan network. In order to do so I am using the fork feature of hardhat and added the following to the hardhat.config.js file:
module.exports = {
solidity: "0.8.0",
defaultNetwork: "hardhat",
networks: {
hardhat: {
forking: {
url: INFURA_URL,
accounts: [`0x${PRIVATE_KEY}`]
}
}
}
};
INFURA_URL points to node on Kovan. PRIVATE_KEY is the key of an account on Kovan I would like to deploy with. This variables work well when I deploy to Kovan directly but not to forked node.
In my deployment script I do the following:
const [deployer] = await ethers.getSigners();
But my deployer is not the account that corresponds to the private key from config. It is a correct account when I deploy directly to Kovan.
Not sure why does this happen are forks of Kovan not supported on hardhat?
The way it worked for me was to forget Hardhat and rely entirely on ethers, for that I created a Signer specifying a private key and a provider like:
import { providers, Wallet } from 'ethers';
require('dotenv').config();
const main = async() => {
const providerLocal = new
providers.JsonRpcProvider("http://127.0.0.1:8545");
const owner = new Wallet(process.env.DEPLOYER_PRIVATE_KEY as string, providerLocal);
console.log(`The wallet ${owner.address} will deploy this contract`)
const MyContract = await ethers.getContractFactory('MyContract');
const mycontract = await MayContract.connect(owner).deploy();
}
main();

Solidity function returning manager address of 0x00000 after contract deployment in Remix IDE

I have recently ran into a bit of an issue with a solidity contract I created and am trying to deploy and interact with inside of the Remix IDE. The function I have written to return the address of the contract manager is as so
function getManager() public view returns(address){
return manager;
}
The way the contract manager is set is as so
function Contest() public {
manager = msg.sender;
}
I have created two JavaScript compile and deploy scripts which I run inside of my terminal. The deploy script is written as this
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const {interface, bytecode} = require('./compile.js');
const provider = new HDWalletProvider(
'MetaMask Mnemonic',
'Infura endpoint key'
);
const web3 = new Web3(provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log('deploying from ', accounts[0]);
const ABI = interface;
const deployedContract = await new web3.eth.Contract(JSON.parse(ABI))
.deploy({data: bytecode})
.send({
gas: '1000000',
from: accounts[0]
});
console.log('contract deployed to', deployedContract.options.address);
}
deploy();
Once my contract is deployed I receive the deployed address (something like 0xbc0370FbC085FAf053b418e6ff62F26ED2C7Dee1) and then I go over to the Remix IDE where I put in the address and use the Injected web3 option. However when I call the "getManager" function it returns an address of 0x0000000000000000000000000000000000000000 and I can't seem to get it to return the address of the manager. This method was working once before and I cannot seem to figure out why it's not working any longer.