I'm currently building a ERC721 compliant contract and have published the contract here: https://ropsten.etherscan.io/address/0xa513bc0a0d3af384fefcd8bbc1cc0c9763307c39 - I'm now attempting to verify and publish the contract source code
The start of my file looks like so:
// SPDX-License-Identifier: MIT
// We will be using Solidity version 0.8.4
pragma solidity 0.8.4;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
contract ViperToken is ERC721 {
However, when attempting to verify and publish with a Solidity single file I have the following error appear:
ParserError: Source "#openzeppelin/contracts/token/ERC721/ERC721.sol" not found: File import callback not supported
--> myc:6:1:
|
6 | import "#openzeppelin/contracts/token/ERC721/ERC721.sol"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Can anyone point me in the direction to either 1. Solve this problem or 2. Documentation on how to appropriately write a contract that has dependencies imported that can be verified with Etherscan. Right now this is just a single file contract.
Simply put I had to go down a rabbit hole to work this out as I'm pretty new to Solidity.
I had to do the following;
Learn and use https://www.trufflesuite.com/ to setup a project and put my contract there (Using Ganache helped a lot with testing for anyone new to Solidity too)
Use HD Wallet provider package and follow tutorial here to get it on ropsten Etherscan https://medium.com/coinmonks/5-minute-guide-to-deploying-smart-contracts-with-truffle-and-ropsten-b3e30d5ee1e
Finally, use truffle-plugin-verify https://github.com/rkalis/truffle-plugin-verify to verify the contract on Etherscan
All in all, I am pretty sure there is no way within the Etherscan web app to verify a contract that contains an imported file.
The final product is here if anyone is interested in seeing how I structured it all https://github.com/lukecurtis93/viper-nft (it's just a CryptoKitties clone I found online as a base and updated it all)
If you are compiling into REMIX IDE
From REMIX IDE
Search for "Flattener" pluging
RIght click the file -> Flatten yourcontract.sol
Copy/Paste on Etherscan
I used npx hardhat flatten to compile all the code into one page, then copy and paste the code into Etherscan's single file verification. I think it is fine if you are just learning to get a feel for verifying your smart contract in Etherscan. But when it comes to production level code, I think OP's solution is better.
npx hardhat flatten gives license identifiers error when trying to verify in etherscan.
Solution is to add the below in hardhat.config.js
task("flat", "Flattens and prints contracts and their dependencies (Resolves licenses)")
.addOptionalVariadicPositionalParam("files", "The files to flatten", undefined, types.inputFile)
.setAction(async ({ files }, hre) => {
let flattened = await hre.run("flatten:get-flattened-sources", { files });
// Remove every line started with "// SPDX-License-Identifier:"
flattened = flattened.replace(/SPDX-License-Identifier:/gm, "License-Identifier:");
flattened = `// SPDX-License-Identifier: MIXED\n\n${flattened}`;
// Remove every line started with "pragma experimental ABIEncoderV2;" except the first one
flattened = flattened.replace(/pragma experimental ABIEncoderV2;\n/gm, ((i) => (m) => (!i++ ? m : ""))(0));
console.log(flattened);
});
An then run npx hardhat flat contracts/ContractToFlatten.sol > Flattened.sol
Related
I deployed a contract of a token that has up to nine other files imported to the finance blockchain. I have done everything I can read and try in order to verify it. But it keeps giving me error.
Compiler debug log:
Error! Unable to generate Contract ByteCode and ABI
Found the following ContractName(s) in source code : Address, Context, IERC20, IUniswapV2Factory, IUniswapV2Pair, IUniswapV2Router01, IUniswapV2Router02, Ownable, RentCoin, SafeMath
But we were unable to locate a matching bytecode (err_code_2)
For troubleshooting, you can try compiling your source code with the Remix - Solidity IDE and check for exceptions
My contract was compiled and deployed using Remix and optimization was set to 200. My compiler version is 0.6.12 and the link to the flattened contract is below:
https://drive.google.com/file/d/100J73q4hutqqmT1tZEuMn46YYFmzYaT0/view?usp=sharing
I understand that this contract involves constructors but I really need a practical guide on how to locate them and convert them to the right-abi-encoded JSON format that the verification page may accept.
I am testing with rinkiby in ethereum geth environment (using light node.). By building the contract with solidity, the contract has been deployed correctly. If I try to access a function in that instance, I got a "match" error. I don't use "match" anywhere in the program source code, but I don't know which part is the problem. Can I analyze more solidity code?
Upgrade your web3 version.
reference.
I'am building a local blockchain using etherium.I wrote a smart contract "Hello" that allows to display a phrase. when I execute truffle.compile an error occurs: No visibility specified. Did you intend to add "public"?
pragma solidity ^0.4.15;
contract Hello{
string public message;
function Hello() {
message = "Hello, World : This is a Solidity Smart Contract on the Private Ethereum Blockchain ";
}
}
Compiling your contracts...
Compiling ./contracts/Hello.sol
Compiling ./contracts/Migrations.sol
/home/mohamed/Projects/Stage/Truffle/contracts/Hello.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.15;
^----------------------^
,/home/mohamed/Projects/Stage/Truffle/contracts/Hello.sol:4:4: SyntaxError: No visibility specified. Did you intend to add "public"?
function Hello1() {
^ (Relevant source part starts here and spans across multiple lines).
Error: Truffle is currently using solc 0.5.0, but one or more of your contracts specify "pragma solidity ^0.4.15".
Please update your truffle config or pragma statement(s).
(See https://truffleframework.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)
Compilation failed. See above.
Truffle v5.0.12 (core: 5.0.12)
Node v8.9.4
Add the following in your truffle config file:
module.exports = {
// your existing config goes here
// don't forget to put comma on the last element before proceeding to next line
compilers: {
solc: {
version: "0.4.25"
}
}
}
Read more about the configuration here. All Solidity versions can be found here.
I have been attempting to deploy a contract using the Truffle framework, I have recently been testing these contracts on the development network.
My contract was very large and when I attempted to deploy it to a test net, I was instructed to split it up so that the contract wouldn't exceed the gas limit. Although, bearing in mind this contract did deploy onto the development network with the default gas limit.
So I took out parts of the contract and derived another contract from the base and added the deleted sections in there. I attempted to deploy it to the development network in order to test it again, I now get the error:
'Error: The contract code couldn't be stored, please check your gas amount.'
So the steps I took was to:
Change my gasLimit to 100,000,000 which didn't solve it
Check to see if my contract is 'abstract'
My understanding of this is that a contract is abstract if it or its
parent has any functions without an implementation. Mine don't.
I then deleted all of the code other than the constructor from the
derived contract and I still get this error
I deleted the file and the deployment worked with just my base contract as before, therefore the parent contract must not have any non-implemented functions AND it still doesn't work when I attempt to derive an empty contract from it (making sure nothing was abstract in the derived contract).
I then split my migration files up so that the migrations happen
separately, still no luck.
My parent contract is around 300 lines long so no point posting it all in here - I know some people will say 'it may just be too large' however, it deployed when it was 500 lines long on the dev network and now it is only 250 lines long with a deriving contract of 275 lines long, it does not deploy.
The error:
Running migration: 2_deploy_contracts.js
Replacing ERC20Token...
... 0xcae613274de1aa278e7ae5d1239f43445132a417d98765a4f227ea2439c9e4fc
ERC20Token: 0xeec918d74c746167564401103096d45bbd494b74
Replacing Crowdsale...
... 0x0ffc7291d84289c1391a81ed9f76d1e165285e3a3eadc065732aa288ea049b3a
Crowdsale: 0x0d8cc4b8d15d4c3ef1d70af0071376fb26b5669b
Saving successful migration to network...
... 0x7f351d76f61f7b801913f59b808688a2567b64933cdfdcf78bb18b0bf4e4ff69
Saving artifacts...
Running migration: 3_more_deployed_contracts.js
Deploying StagedSale...
... 0x216136bb24d317b140a247f10ec4d6791559739111a85932133cd4a66b12a1d9
Error encountered, bailing. Network state unknown. Review successful
transactions manually.
Error: The contract code couldn't be stored, please check your gas
amount.
at Object.callback
(/usr/local/lib/node_modules/truffle/build/cli.bundled.js:329221:46)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:39618:25
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:331159:9
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:175492:11
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:314196:9
at XMLHttpRequest.request.onreadystatechange
(/usr/local/lib/node_modules/truffle/build/cli.bundled.js:329855:7)
My base contract is too large to post, and it deploys fine on its own meaning its not abstract.
My derived contract is:
pragma solidity ^0.4.16;
import "./SafeMath.sol";
import "./Crowdsale.sol";
contract StagedSale is Crowdsale {
using SafeMath for uint256;
/*
* Setup the contract and transfer ownership to appropriate beneficiary
*/
function StagedSale
(
uint256 _stage1Duration,
uint256 _stage2Duration
) public {
uint256 stage1duration = _stage1Duration.mul(1 minutes);
uint256 stage2duration = _stage2Duration.mul(1 minutes);
}
My migration file for the derived contract:
var StagedSale = artifacts.require("./StagedSale.sol");
module.exports = function(deployer) {
const stage1Duration = 1;
const stage2Duration = 1;
deployer.deploy(StagedSale, stage1Duration, stage2Duration);
};
I have posted this question here as I fear this may be a common issue with Truffle deployment.
To conclude, I don't believe this has anything to do with the actual gas limits and is instead, failing for some unknown reason and printing this error message anyway.
I've found a fix to this, basically if you are inheriting from a base contract, you must deploy the base contract within the inherited contracts constructor like so:
OLD VERSION:
Simply deployed the base, then deployed the inheriting contract with a reference to 'is Crowdsale' in class name
deployer.deploy(ERC20Token, initialAmount, tokenName, decimalUnits,tokenSymbol).then(function() {
return deployer.deploy(Crowdsale, softCap, hardCap, etherCostOfEachToken, sendFundsTo, toChecksumAddress(ERC20Token.address), durationInMinutes);
});
deployer.deploy(FinalizableSale);
NEW VERSION
Only deploy the inheriting contract and create a new instance of base within that constructor
deployer.deploy(ERC20Token, initialAmount, tokenName, decimalUnits,tokenSymbol).then(function() {
return deployer.deploy(Finalizable, softCap, hardCap, etherCostOfEachToken, sendFundsTo, toChecksumAddress(ERC20Token.address), durationInMinutes);
});
FINALIZABLE CONSTRUCTOR:
function FinalizableSale(uint256 _fundingGoalInEthers, uint256 _fundingLimitInEthers, uint256 _etherCostOfEachToken, address _sendFundsTo, address _tokenAddress, uint256 _durationInMinutes)
Crowdsale(_fundingGoalInEthers, _fundingLimitInEthers, _etherCostOfEachToken, _sendFundsTo, _tokenAddress, _durationInMinutes)
{
//do something
}
NOTE: That the base contract is initialised BEFORE the opening brackets to the constructor function.
I no longer get the 'out of gas' error and my contract runs as before.
Trying to follow the wiki example for go ethereum to create a basic contract:
https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions
Everything seems to work until I get down until the last line:
source = "contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"
contract = eth.compile.solidity(source).test
primaryAddress = eth.accounts[0]
# **Problems start here **
MyContract = eth.contract(abi);
contact = MyContract.new(arg1, arg2, ...,{from: primaryAddress, data: evmCode})
What is the "abi" argument for the eth.contract method? Also, what would I put in the "evmCode" argument? In this particular example, seems like I would put in an integer for "arg1" but not sure what the full example should look like.
The ABI is the interface that your contract exposes. "evmCode" is the Ethereum byte code for your contract.
To work around your problem, go to https://chriseth.github.io/browser-solidity/ and plug your Solidity in. The Bytecode field on the right will give you the value for "evmCode" and Interface will give you the ABI.
You can also copy the snippet from "Web3 deploy" and paste it in your code to deploy your contract.
ABI is basically which is the public facing interface that shows what methods are available to call.
The simplest way to get the abi would be to use https://remix.ethereum.org . just paste in your code and in Contract tab At the bottom of the column you’ll find a link that says Contract details which is basically the ABI json
Conversely you could also use the contracts.Introduction.interface api of web3 to get the abi.
ABI is representation of smart contract that can be read using java script .To read the data from a deployed contract account in etherum , you'll need some extra details like abi.
Steps to get abi of any smart contract:
1.Each contract has contract hash address like this:0x0D8775F648430679A709E98d2b0Cb6250d2887EF
2.Go to etherscan.io and search your contract address hash in search bar and you will get contract.
3.In contract go to code and there you can find this abi
can check this link to find abi
You could try using tools like Etherlime shape or Truffle boxes to have a whole sample project with contract, tests, and usage into the js. From here you could start moving forward.
ABI is Application Binary Interface. A contract when compiled by solidity compiler returns an object with different methods. ABI and Bytecode are basically used methods. ABI is used to interact with your contracts and frontend (if using node) and bytecode is used for deploying to Rinkeby (or any Ethereum network).
For example:
Contract is:
pragma solidity ^0.4.17;
contract Inbox
{
string public message;
function Inbox(string initialMessage) public{
message = initialMessage;
}
function setMessage(string newMessage) public{
message = newMessage;
}
}
Its ABI is:
interface:
[{
"constant":false,"inputs":[{
"name":"newMessage","type":"string"
}]
,"name":"setMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"
}
,{
"constant":true,"inputs":[],"name":"message","outputs":[{
"name":"","type":"string"
}]
,"payable":false,"stateMutability":"view","type":"function"
}
,{
"inputs":[{
"name":"initialMessage","type":"string"
}]
,"payable":false,"stateMutability":"nonpayable","type":"constructor"
}]
This is returned after compiling the contract. You can see it consists of methods used in our contract.