trying to compile this on remix and I keep getting this a parse error saying expected '(' but got identifier - solidity

constructor() ERC721("MYNFT", "MYCOLLECTION")
{
function GenerateNFT(
string calldata ItemName,
string calldata description,
uint256[6] calldata Magic
) public payable virtual {

Related

when i am running code in remix id it does not give error while in vs code it gives me error after installation solidity extension

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
contract Transactions {
uint256 transactionCount;
event Transfer(address from, address receiver, uint amount, string message, uint256 timestamp, string keyword);
struct TransferStruct {
address sender;
address receiver;
uint amount;
string message;
uint256 timestamp;
string keyword;
}
TransferStruct[] transactions;
function addToBlockchain(address payable receiver, uint amount, string memory message, string memory keyword) public {
transactionCount += 1;
transactions.push(TransferStruct(msg.sender, receiver, amount, message, block.timestamp, keyword));
emit Transfer(msg.sender, receiver, amount, message, block.timestamp, keyword);
}
function getAllTransactions() public view returns (TransferStruct[] memory) {
return transactions;
}
function getTransactionCount() public view returns (uint256) {
return transactionCount;
}
}
If the code doesn't provide error in Remix, its fine. Solidity extensions/linters in VSCode are not a reliable source of errors.

Does the order of memory arguments in the Solidity function matter?

i'm trying to make the simple storage using Solidity. Here I'm just trying to map name to some number.
The problem is the following: if I use store_first() it does not work (the retrieve() function returns 0 in any case). But if I change the order of the arguments and place the string memory _name before uint256 _favoriteNumber everything works (the retrieve() function returns correct number)
Does the problem relates to the order (if yes, why?) or I missed something else?
// SPDX-License-Identifier: MIT
pragma solidity >0.6.0;
contract SimpleStorage {
mapping(string => uint256) public nameToNumber;
// If i use this function, the retrieve function always returns 0
function store_first(uint256 _favoriteNumber, string memory _name) public {
nameToNumber[_name] = _favoriteNumber;
}
// If i use this function, the retrieve function returns correct number
function store_second(string memory _name, uint256 _favoriteNumber) public {
nameToNumber[_name] = _favoriteNumber;
}
function retrieve(string memory _name) public view returns(uint256){
return nameToNumber[_name];
}
}

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)

TypeError: Data location can only be specified for array, struct or mapping types, but "calldata" was given

I created a function that stores data. But this function cannot receive data. I tried it without calldata, with memory but all this ways didn't work. Thanks for the help.
pragma solidity >=0.7.0 <0.9.0;
contract Test {
struct Messanges{
string message;
address sender;
}
Messanges[] public chatverlauf;
address a = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
function add(string calldata _message, address calldata _sender) public{
//chatverlauf.push(Messanges(_message, _sender));
Messanges memory newMessage;
newMessage.message = _message;
newMessage.sender = _sender;
chatverlauf.push(newMessage);
}
i lookt up in this but it didn't workt for me
https://ethereum.stackexchange.com/questions/83602/data-location-can-only-be-specified-for-array-struct-or-mapping-types-but-mem/83603
written with remix
the compiler version is 0.8.10
change
function add(string calldata _message, address calldata _sender) public
to
function add(string _message, address _sender) public
In Solidity 0.8.0 only array , struct and mapping type can specific data location.

How to store in an orders contract an array of products contract

I'm new to solidity and the whole blockchain concept and I'm trying to do a simple e-commerce website where a user can select some products, put them in his basket and place an order.
The problem is I don't know how to make this work. I'm trying to initialize the order contract with a mock order that contains an array of products, but I'm getting TypeErrors such as this:
"TypeError: Member "createProduct" not found or not visible after argument-dependent lookup in type(contract Products)."
Here is my Products.sol
pragma solidity ^0.5.0;
contract Products {
uint256 public productsCount = 0;
struct Product {
uint256 id;
string name;
string category;
int256 price;
}
mapping(uint256 => Product) public products;
event ProductCreated(
uint256 id,
string name,
string category,
int256 price
);
event ProductEdited(uint256 id, string name, string category, int256 price);
event ProductDeleted(
uint256 id,
string name,
string category,
int256 price
);
constructor() public {
createProduct("Test", "Test", 53);
}
function createProduct(
string memory _name,
string memory _category,
int256 _price
) public {
productsCount++;
products[productsCount] = Product(
productsCount,
_name,
_category,
_price
);
emit ProductCreated(productsCount, _name, _category, _price);
}
function editProduct(
uint256 _id,
string memory _name,
string memory _category,
int256 _price
) public {
Product memory _product = products[_id];
_product.name = _name;
_product.category = _category;
_product.price = _price;
products[_id] = _product;
emit ProductEdited(_id, _name, _category, _price);
}
function deleteProduct(uint256 _id) public {
Product memory _product = products[_id];
delete products[_id];
productsCount--;
emit ProductDeleted(
_id,
_product.name,
_product.category,
_product.price
);
}
}
And here is my Orders.sol
pragma solidity ^0.5.0;
import "./Products.sol";
contract Orders {
uint256 public ordersCount = 0;
struct Order {
uint256 id;
int256 totalPrice;
string date;
Products[] products;
}
mapping(uint256 => Order) public orders;
constructor() public {
createOrder(
150,
"01.01.2021",
[Products.createProduct("name", "category", 1)]
);
}
function createOrder(
int256 _totalPrice,
string memory _date,
Products[] memory _products
) public {
ordersCount++;
orders[ordersCount] = Order(ordersCount, _totalPrice, _date, _products);
}
}
Probably it's a simple question but I've never used solidity before and all the tutorials on youtube are too simple and don't explain this kind of nested datas.
I'd really appreciate some help here :D
Your createProduct method returns nothing. It is for this reason that it does not work. You can change your method like
function createProduct(
string memory _name,
string memory _category,
int256 _price
) public returns (Product) {
productsCount++;
products[productsCount] = Product(
productsCount,
_name,
_category,
_price
);
emit ProductCreated(productsCount, _name, _category, _price);
return products[productsCount];
}
Or you can create another method that will call createProduct to create a product and then return it.
I think that the error is that you are treating the contract as they were classes.
To access a contract from another contract you have to instantiate it with it address.
You could store the products id in order contract and interact with products contract when you need to get products information.
If you want to create products with order contract you should do something like this
function createProduct(address addr) public {
Products p = Products(addr);
p.createProduct("name", "category", 1);
}