Verifying a Contract on BSCScan.com - solidity

I created a cryptocurrency with the help of a friend of mine (it took us ages to copy-paste codes from here and there) and to edit the contract's info, which is crucial for me, I now need to verify the contract. Here's my contract address:
0xe1c7a0d5e099a1f0c14b60b0c320423cf2f4543b
and here is the code I used in Remix:
pragma solidity >=0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract HelpingArtistsAtRisk is ERC20 {
constructor(uint256 initialsupply) public ERC20 ("Helping Artists At Risk", "HAAR"){
_mint(msg.sender,initialsupply);}
}
It gives me error after error when I try to verify it. Here are the error messages:
Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: " to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> myc
ParserError: Source "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported
--> myc:3:1:
|
3 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol"
BEP-20.sol:1:1: Error: Compiler version >=0.8.0 does not satisfy the r semver requirement
ParserError: Expected pragma, import directive or contract/interface/library/struct/enum/constant/function definition.
--> myc:1:1:
|
1 | "SPDX-License-Identifier: UNLICENSED"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I just wanted to have the BSCSCAN's verification.

Since solidity 0.6.8 you should set a License header to your contract, so you need to add this at the first line of your file:
// SPDX-License-Identifier: UNLICENSED
You can use the UNLICENSED or use one of the predefined licenses. Here is the list: https://spdx.org/licenses/
More information about the SPDX License herader here: https://forum.openzeppelin.com/t/solidity-0-6-8-introduces-spdx-license-identifiers/2859
This should fix your first Warning and the last error.
After making this change I was able to compile the contract using remix, but I think that all other errors are related with the compiler version, could you share version and other settings that you see in the compiler options?
I'm using Compiler 0.8.4+commit.c7e474f2
Also you need to remove the public keyword in the constructor, it is ignored by the compiler. The final result is:
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract HelpingArtistsAtRisk is ERC20 {
constructor(uint256 initialsupply) ERC20 ("Helping Artists At Risk", "HAAR"){
_mint(msg.sender,initialsupply);}
}

Related

Get pool balances from BalancerV2 in Solidity

I am trying to inspect the pool balances of a decentralized exchange called Balancer. The implementation is done with the main version V2.
I want to get the pool balance with
vault.getPoolTokens(0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014);
The contract looks like this:
contract BalancerV2 {
IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8";
function getPoolTokens() public view returns(uint) {
return vault.getPoolTokens(0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014);
}
}
But it gives me the following error message:
from solidity:
contracts/BalancerV2.sol:8:37: TypeError: Type literal_string "0xBA12222222228d8Ba445958a75a0704d566BF2C8" is not implicitly convertible to expected type contract IVault.
IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8";
^------------------------------------------^
My question is:
How is it possible that even in the official GitHub repository they have a working example of how to initialize the vault with solidity compiler version 0.7.0 and I'm literally trying the same with getting this error?
By the way, the example in the documentation has a typo so it won't compile. Just in case if someone from the devs sees this.
https://dev.balancer.fi/resources/pool-interfacing#pool-balances
I am trying to compile this contract and am expecting to get this result:
tokens: [0xba100000625a3754423978a60c9317c58a424e3D,
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2]
balances: [5720903090084350251216632,
7939247003721636150710]
Instead of:
IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8";
try this:
IVault private constant vault = IVault(0xBA12222222228d8Ba445958a75a0704d566BF2C8);

solidity : bytecode optimization : require( condition ) issue

I have a solidity code which uses an optimization=200 in remix.
I'm suspicious if optimization is buggy on my code.
when I use for example :
mapping(address => uint8) allowedUsers;
function doSomething(address wallet) external {
...
require( allowedUsers[wallet]!=1, "User already set" );
allowedUsers[wallet]=1;
...
if I run it on binance mainnet or under rinkeby, there is no issue.
But sometimes randomly when used on ethereum mainnet I'm getting
revert error "User already set".
What is strange, It occurs on the first function call for a wallet. But not always.
It seems mapping & require have issues together. because it can occur on another require with mapping not just as on this example.
I cannot disable optimization since bytecode is nearly 25400 bytes out of 25476 allowed.
Any idea what's wrong?
I'm using solidity 0.8.15
The issue was something completely different, and was happening in the ethereum mempool.
I understand what happened : I've been front-runned by a MEV BOT. It detected an ETH transaction was sent from my smartcontract, and sent a copy-cat of the transaction earlier than mine.
I've put counter-actions to avoid it. it's okay now.

what is the difference between these two ethers.js functions [duplicate]

Can somebody please point me to the documentation (official or otherwise ) that explains the function ethers.getContractAt():
the original context of this is as follows:
vrfCoordinator = await ethers.getContractAt('VRFCoordinatorMock', VRFCoordinatorMock.address, signer)
and the full code can be found here...
https://github.com/PatrickAlphaC/all-on-chain-generated-nft/blob/main/deploy/02_Deploy_RandomSVG.js
In the absence of such documentation, an explanation would be much appreciated. Thank you!
The getContractAt() function is part of the hardhat-ethers plugin for Hardhat, expanding the ethers object.
It's not a part of the core Ethers package, so it's not included in their documentation.
Hardhat docs mentioning the plugin: https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#helpers
Basically, it is doing the same thing, that attach do but in one line. i.e you can actually interact with an already deployed contract.
For reference below is the code if you are using attach
let xyzContract = await hre.ethers.getContractFactory("Name of the contract");
let xyzContractInstance = xyzContract.attach('Address of the contract');
You can accomplish the same thing in one line via getContractAt() when using hardhat
let xyzContractInstance = await hre.ethers.getContractAt(
"Contract Address",
deployed contract address
);

Source "#chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol" not found: File import callback not supported

I saw a lot of issues on this same problem and tried them all but it still doesnt solve the callback issue for me.
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "#chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "#chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";
contract FundMe {
using SafeMathChainlink for uint256;
error message doesn't go away for me
this is my brownie-config.yaml file
dependencies:
# -<organization/repo>#<version>
- smartcontractkit/chainlink-brownie-contracts#1.1.1
compiler:
solc:
remappings:
- "#chainlink=smartcontractkit/chainlink-brownie-contracts#1.1.1"
after that I compiled and it was successful but the errors wouldnt go away.
brownie-compile
Any help on this would be EPIC.
Thank you in advance
The compiler doesn't know where is the file so just create a new folder inside contracts folder named tests and then create a new file naming: AggregatorV3Interface.sol and then paste this code inside it :
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
After this recompile the project and then run, it will run without any errors and you will get the result.
For more information visit :: this question
I had same issue. This is what solved the problem on my system :
i checked the solicity version i had installed through 'nmp -g list' in the terminal. It seemed that i had version 0.8.xx installed.
i downgraded to version 0.6.6 through 'npm install -g solc#0.6.6'
i rechecked the installed version and it gave me this :
enter image description here
the i compiled throught 'brownie compile' and it worked, even though is still had the 'red lines' telling about an issue in the file. Json file was generated
Hope this helps, have been searching for a while.
I did fix this by asking the IDE I’m using (Visual Studio Code) to use the version of interface v0.7 as I wanted to import the v0.7 interface:
#chainlink/contracts/src/v0.7/interfaces/AggregatorV3Interface.sol
FYI: I am following a YouTube tutorial that tells you to remap the #chainlink to a git path from release 1.1.1, but the interface files are zipped now, hence I choose v0.7 where files are still available.
I had the same issue just try changing solidity version to 0.8.7 and version of chainlink to 0.8
pragma solidity ^0.8.7;
import "#chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

create a new contract in solidity

I have a called contract, and a calling contract. The calling contract needs to create the called contract on the fly. It should be easy to do by
CalledContract c = new CalledContract()
in your solidity code. However, the complication is that the called contract also uses a library, and the trufflesuite will complain that the library needs to be linked before I can create a new called contract on the fly in the calling contract body.
Have you specified the link before you run migrations and deploy the contracts?
something like below?
// 3 files
contractA.sol
contractB.sol
library.sol
// your migration file, #_something.js
import "contractA.sol";
import "contractB.sol";
import "library.sol";
module.exports = function(deployer) {
deployer.deploy(library_name);
deployer.autolink();
deployer.deploy(contractA);
deployer.deploy(contractB);
};