Can you please tell me why I'm getting this error message on solidity - solidity

[https://i.stack.imgur.com/uSU0Y.png][1]
from solidity:
DeclarationError: Identifier already declared.
--> contracts/MySimpleStorage.sol:16:5:
|
16 | people[] public people;
|
Note: The previous declaration is here:
--> contracts/MySimpleStorage.sol:11:5:
|
11 | struct people {
| (Relevant source part starts here and spans across multiple lines).
error 2
from solidity:
TypeError: Expected callable expression before call options.
contracts/MySimpleStorage.sol:32:21:
|
32 | people.push(people{favoriteNumber: _favoriteNumber, name: _name});
check the above link for screenshot
here's the main code
`// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract MySimpleStorage {
//this will get initilized to 0 since we did not state the number
uint256 public favoriteNumber;
bool favoriteBool;
struct people{
uint256 favoriteNumber;
string name;
}
People[] public people;
mapping(string => uint256) public nameToFavoriteNumber;
function store(uint256 _favoriteNumber) public {
favoriteNumber = _favoriteNumber;
}
function retrieve() public view returns(uint256) {
return favoriteNumber;
}
function addPerson(string memory _name, uint256 _favoriteNumber) public{
people.push(people(_favoriteNumber, _name));
nameToFavoriteNumber[_name] = _favoriteNumber;
}
}`

This issue is from case sensitivity. you have declared struct with lower case here -struct people
You will need to declare same before the dynamic array here-People[]
Lowercase here is your object name that appears on the button in public, and this could be anything -public people
Bottonname.push(structNAME...

Related

TypeError: Member "mint" not found or not visible after argument-dependent lookup in address

I'm trying to compile this contract but it won't work. I know I can point mint and redeem for address, but since I'll get these from compound, how do I point it to make it compile?
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;
import "#openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import "#openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import {OwnableUpgradeable} from "#openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
contract Myvaultis ERC4626Upgradeable, OwnableUpgradeable {
//compound variable to store address
address _cAsset;
function initialize(
IERC20MetadataUpgradeable asset_,
string memory name_,
string memory symbol_
) public initializer {
__MyVault_init(asset_, name_, symbol_);
_cAsset = 0x00000000000000000000000; //put here cAsset address
}
function __MyVault_init(
IERC20MetadataUpgradeable asset_,
string memory name_,
string memory symbol_
) internal onlyInitializing {
__ERC4626_init_unchained(asset_);
__ERC20_init_unchained(name_, symbol_);
__Ownable_init_unchained();
}
function depositCompound(
IERC20MetadataUpgradeable asset_,
address cAsset_,
uint256 _amount
) public onlyOwner returns (uint) {
asset_.approve(cAsset_, _amount);
// Mint cTokens
uint mintResult = cAsset_.mint(_amount);
return mintResult;
}
function withdrawCompound(
uint256 amount,
bool redeemType,
address cAsset_
) public onlyOwner returns (bool) {
uint256 redeemResult;
if (redeemType == true) {
redeemResult = cAsset_.redeem(amount);
} else {
redeemResult = cAsset_.redeemUnderlying(amount);
}
return true;
}
}
The error i'm getting is
TypeError: Member "mint" not found or not visible after argument-dependent lookup in address.
|
38 | uint mintResult = cAsset_.mint(_amount);
| ^^^^^^^^^^^^
Error HH600: Compilation failed
looks like you haven't defined the contract and your trying to access it via the address.
You might have to define the interface then plug in the address.
contract = interface(address)
then you can use contract.functionName(parameters)

Definition of base has to precede definition of derived contract (ERC721 implementation)

The top SO or ETH Stack Exchange answers don't seem to apply to my case (I could be wrong of course)
I'm getting the error describer in the title in this file:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ERC721Metadata.sol";
import "./ERC721.sol";
contract ERC721Connector is ERC721Metadata, ERC721 {
// ^^^^^^^ (Definition of base has to precede definition of derived contract)
constructor(string memory name, string memory symbol) ERC721Metadata(name, symbol) {}
}
Here's what ERC721Metadadata looks like:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract ERC721Metadata {
string private _name;
string private _symbol;
constructor(string memory named, string memory symbolified) {
_name = named;
_symbol = symbolified;
}
function name() external view returns (string memory) {
return _name;
}
function symbol() external view returns (string memory) {
return _symbol;
}
}
And here is what ERC721 looks like:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ERC721Metadata.sol";
import "./ERC721Connector.sol";
contract ERC721 {
event Transfer(
address indexed from,
address indexed to,
uint256 indexed tokenId
);
mapping(uint256 => address) private _tokenOwner;
mapping(address => uint256) private _OwnedTokensCount;
function _exists(uint256 tokenId) internal view returns (bool) {
address owner = _tokenOwner[tokenId];
return owner != address(0);
}
function _mint(address to, uint256 tokenId) internal {
require(to != address(0), "ERC721: minting to the zero address");
require(
!_exists(tokenId),
"ERC721: minting a token that already exists (been minted)"
);
_tokenOwner[tokenId] = to;
_OwnedTokensCount[to] += 1;
emit Transfer(address(0), to, tokenId);
}
}
Do you need to import ERC721Connector contract in your ERC721 contract? If not, you can remove
import "./ERC721Connector.sol"; // line 4, ERC721.sol
from your file and it should work fine. Your imports are causing the issue,
ERC721Connector tries to import ERC721, but ERC721 also needs ERC721Connector so the compiler says
Definition of base has to precede definition of derived contract
Because the base contract doesn't precede the defined contract.

Error in solidity code: Return argument type bytes1 is not implicitly convertible to expected type

I have setter and getter:
function setFunc(bytes calldata _value) public {
getBytes = _value;
}
function getFunc() public view returns(bytes calldata) {
return getBytes;
}
When I run my code, the compiler shows that
TypeError: Return argument type bytes1 is not implicitly convertible to expected type (type of first return variable) bytes calldata.
--> contracts/GetterSetter.sol:38:16:
|
38 | return getBytes[];
| ^^^^^^^^^^
Before that I had another error:
TypeError: Data location must be "memory" or "calldata" for return parameter in function, but none was given.
--> contracts/GetterSetter.sol:37:51:
|
37 | function requestedBytes() public view returns(bytes) {
| ^^^^^
Could you help to resolve it and what input example should I provide into setter for correct functions working?
I will be really appreciate for your help!
The getter function return type needs to have the memory data location.
It's because the EVM loads the value from storage to memory, and then returns it from memory.
pragma solidity ^0.8;
contract MyContract {
bytes getBytes;
function setFunc(bytes calldata _value) public {
getBytes = _value;
}
function getFunc() public view returns(bytes memory) {
return getBytes;
}
}
The return type could have the calldata location only if it's returning the actual and unchanged calldata from the input param:
pragma solidity ^0.8;
contract MyContract {
function getFunc(bytes calldata _value) public pure returns(bytes calldata) {
return _value;
}
}
Hm.. I tried in Remix and it looks like woks as it should, but when I run it with Hardhat, it returns Zero.
await getset.setBytes32('0x7465737400000000000000000000000000000000000000000000000000000000');
const getBytes32 = await getset.requestedBytes32();
console.log('Bytes32:', getBytes32);

why this error always on? Identifier not found or not unique

pragma solidity ^0.8.6;
contract mycontract{
address owner;
string name;
bool visible;
uint16 count;
constructor ()public {
owner=msg.sender;
}
function changname (stringmemory _name) public returns (stringmemory){
if(msg.sender==owner){
name=_name;
return "sucsesss";
}else{
return "acsess denid";
}
}
function showname () view public returns(stringmemory){
return name;
}
}
hey guuys i write this codes down but i gut the blow error what should i do now pls help me thank you
this project its belong to my university and if i lost in it i will fail my exam and im bechokh miram toro khoda komak konid thank you
i got some warning too what is this ?
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.
--> browser/test.sol
DeclarationError: Identifier not found or not unique.
--> browser/test.sol:14:21:
|
14 | function changname (stringmemory _name) public returns (stringmemory){
| ^^^^^^^^^^^^
It has a couple of bugs in its code.
builder visibility is not required
in the parameters of its functions it has a bad type
'stringmemory' the variable would be type 'sting' and it would be read from memory.
In this way your code would look like this:
pragma solidity ^0.8.6;
contract mycontract{
address owner;
string name;
bool visible;
uint16 count;
constructor () {
owner=msg.sender;
}
function changname (string memory _name) public returns (string memory){
if(msg.sender==owner){
name=_name;
return "sucsesss";
}else{
return "acsess denid";
}
}
function showname () view public returns(string memory){
return name;
}
}

Error when i click my "people" button. I can sucessfully "addPerson" but the information is not saved

call to SimpleStorage.people errored: Error encoding arguments: Error: invalid BigNumber string (argument="value" value="" code=INVALID_ARGUMENT version=bignumber/5.5.0)
Thank you anyone for their time.
pragma solidity ^0.6.0;
contract SimpleStorage {
// 0 is fav number.
uint256 favoriteNumber;
bool favoriteBool;
struct People {
uint256 favoriteNumber;
string name;
}
People[] public people;
function store(uint256 _favoriteNumber) public {
favoriteNumber = _favoriteNumber;
}
function retrieve() public view returns(uint256) {
return favoriteNumber;
}
function addPerson(string memory _name, uint256 _favoriteNumber) public{
people.push(People(_favoriteNumber, _name));
}
}
People is an array, so you need to specify the index of the array first.
So if you want to access the first person, you have to specify 0 (index begins with 0) in the input box next to the person button.