Solidity: Declaration Error: identifier not found or not unique. mapping(string=> team) teams; ^_ _^ - solidity

This is my first time to write a computer programming language and it's a smart contract.
After finish, I pressed compile, and it shows the following error: DeclarationError: Identifier not found or not unique.
mapping(string=> team) teams;
^_ _^
Please anyone help me to find out what is the problem?
My smart contract as below:
// spdx-license-identifier: MIT
pragma solidity ^0.7.0;
contract Database {
struct Team {
string engineer;
mapping (string=>uint) numbers;
}
mapping(string=>team) teams;
function addTeams(string calldata teamName, string calldata engineer) public {
Team storage team = teams [teamName];
team.engineer = engineer;
}
function addDrawingNumber(string calldata teamName, string calldata engineerName, uint number) public {
Team storage team = teams [teamName];
team.numbers[engineerName] = number;
}
function getDrawingNumber(string calldata teamName, string calldata engineerName) public view returns (uint) {
Team storage team = teams [teamName];
return team.numbers[engineerName]
; }
}

Solidity is a case-sensitive language. You have defined a struct type Team (capital T) - but in the mapping you're trying to use a type team (lowercase t), which is not defined.
Solution: Unify the case sensitivity.
struct Team {
string engineer;
mapping (string=>uint) numbers;
}
mapping(string=>Team) teams;

Related

What is the meaning of comma sequence like ,,,,, in Solidity?

I recently came across the following Solidity function:
function testHealthFactor() public {
(, , , , , uint256 healthFactor) = ILendingPool(lendingPool).getUserAccountData(user);
console.log("health factor", healthFactor);
assertEq(healthFactor < 1 ether, true);
}
I don't know Solidity enought yet, so I wander what is the mining of that sequence of 5 commas?
Solidity allows you to return multiple values within a function. If you don't need these values, you can omit them, and move to the next with the ,.
For example:
function returnStuff() public returns (uint256, uint256) {
return (1, 3);
}
( , uint256 ourNum) = returnStuff();
// ourNum = 3

How can uniswapV2Library pairFor addres be different from uniswapV2Factory getPair for same tokens?

I'm writing a Solidity smartcontract.
Working on Kovan testnet.
I understood from the Uniswap documentation, that the .pairFor method from the uniswapV2Library contract should return an address for this pair of tokens.
For free, since it's not making external calls, it's calculating inside.
And that .getPair method on the uniswapV2Factory should do the same, but via a request that costs gas.
However, both methods return a different address, and I can't understand how that is possible.
Can somebody explain what I'm missing?
This is my contract (i simplified it a bit), most important is the repl function:
pragma solidity =0.8.12;
import './UniswapV2Library.sol';
import './interfaces/IUniswapV2Router02.sol';
import './interfaces/IUniswapV2Pair.sol';
import './interfaces/IUniswapV2Factory.sol';
contract FlashLoaner {
address immutable factory;
IUniswapV2Router02 immutable sushiRouter;
IUniswapV2Factory immutable factoryV2;
address public var1;
address public var2;
address public resultPair;
address public resPair2;
address public fact;
constructor(address _factory, address _uniRouter, address _sushiRouter) public {
factory = _factory;
sushiRouter = IUniswapV2Router02(_sushiRouter);
factoryV2 = IUniswapV2Factory(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f);
}
function repl(address _sender, uint _amount0, uint _amount1) external {
//0x052AE8b0F7E5c610937920e46ED265c2063Cb7B8 = uniswapV2pair WETH RAI
address msgsender = 0x052AE8b0F7E5c610937920e46ED265c2063Cb7B8;
IUniswapV2Pair v2Pair = IUniswapV2Pair(msgsender);
address token0 = v2Pair.token0();
address token1 = v2Pair.token1();
//uniswap v2 factory address
fact = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
//results in 0x3c8B7Cf2bDCC9DEB44a72f40052ae8b0F7E5C610
//which i don't understand??
resultPair = UniswapV2Library.pairFor(fact, token1, token0);
//results in 0x052AE8b0F7E5c610937920e46ED265c2063Cb7B8 = uniswapV2pair WETH RAI
//which makes total sense
resPair2 = factoryV2.getPair(token0, token1);
}
}
Why is resPair2 not the same as resultPair??

gas estimation errored with message: "execution reverted: Below agreed payment"

I am having issues when trying to use the Chainlink random number generator and deploying to Rinkeby. Relevant code pieces are the following:
Constructor from the importing contract (should be working fine).
// RandomNumberConsumer parameters for RINKEBY testnet
address _vrfCoordinator = 0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B;
address _link = 0x01BE23585060835E02B77ef475b0Cc51aA1e0709;
bytes32 _keyHash = 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311;
uint256 _fee = 0.1 * 10 ** 18; // 0.1 LINK
constructor() RandomNumberConsumer(_vrfCoordinator, _link, _keyHash, _fee) {}
RandomNumberConsumer.sol. As specified in the chainlink docs, with a few tweaks needed for my approach.
pragma solidity ^0.8.7;
import "#chainlink/contracts/src/v0.8/VRFConsumerBase.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
import "hardhat/console.sol";
contract RandomNumberConsumer is VRFConsumerBase, Ownable{
// Variables
bytes32 internal s_keyHash;
uint256 internal s_fee;
uint256 private constant ROLL_IN_PROGRESS = 150;
mapping(bytes32 => address) private s_rollers;
mapping(address => uint256) private s_results;
//address vrfCoordinator = 0x3d2341ADb2D31f1c5530cDC622016af293177AE0;
//address link = 0xb0897686c545045aFc77CF20eC7A532E3120E0F1;
// Events
event DiceRolled(bytes32 indexed requestId, address indexed roller);
event DiceLanded(bytes32 indexed requestId, uint256 indexed result);
/**
* Constructor inherits VRFConsumerBase
*
* Network: Rinkeby
* Chainlink VRF Coordinator address: 0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B
* LINK token address: 0x01BE23585060835E02B77ef475b0Cc51aA1e0709
* Key Hash: 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311
*/
constructor(address vrfCoordinator, address link, bytes32 keyHash, uint256 fee)
VRFConsumerBase(vrfCoordinator, link){
s_keyHash = keyHash;
s_fee = fee;
}
// Functions
function rollDice(address roller) public onlyOwner returns (bytes32 requestId){
console.log("RNG Contract address",address(this));
// Checking LINK balance
require(LINK.balanceOf(address(this)) >= s_fee, "Not enough LINK in contract.");
// Checking if roller has already rolled dice since each roller can only ever be assigned to a single house. TODO: this can be changed
require(s_results[roller] == 0, "Already rolled");
// Requesting randomness
requestId = requestRandomness(s_keyHash, s_fee); // Error is happening here!
// Storing requestId and roller address
s_rollers[requestId] = roller;
// Emitting event to signal rolling of dice
s_results[roller] = ROLL_IN_PROGRESS;
emit DiceRolled(requestId, roller);
}
// fulfillRandomness is a special function defined within the VRFConsumerBase contract that our contract extends from.
// The coordinator sends the result of our generated randomness back to fulfillRandomness.
function fulfillRandomness(bytes32 requestId, uint256 randomness) override internal {
// Transform the result to a number between 0 and 100, both included. Using % as modulo
require(randomness!=0, "Modulo zero!");
uint256 d100Value = (randomness % 100) + 1; // +1 so s_results[player] can be 0 if no dice has been rolled
// Assign the transformed value to the address in the s_results mapping variable.
s_results[s_rollers[requestId]] = d100Value;
// Emit a DiceLanded event.
emit DiceLanded(requestId, d100Value);
}
// playerWins determines whether the player wins or lose the battle, based on a fixed chance (0-100)
function playerWins (address player, uint8 chance) internal view returns (bool wins){
require(s_results[player] != 0, "Player has not engaged in battle!");
require(s_results[player] != ROLL_IN_PROGRESS, "Battle in progress!");
return s_results[player] <= (chance + 1); //+1 because dice is 1-101
}
}
RNG call from the importing contract(simplified to relevant part only. _player address is working correctly).
address _player = ownerOf(_monId);
rollDice(_player);
I have the certainty that the error occurs inside the rollDice function, more specifically in the call to requestRandomness. Apart from that, I cannot seem to find why the error is hapenning, nor any references to the error message (Below agreed payment) inside any of the dependency contracts. Cannot find any references online either.
Any help is appreciated, thanks.
Below agreed payment error message comes from the sufficientLINK modifier of the VRFCoordinator.sol contract. You can see it here and here.
Double-check the constructor parameters, especially the fee value.
Also, make sure to fund your smart contract with Rinkeby LINK tokens which you can claim from the faucet.

How to set msg.value in Remix IDE

This is probably an easy error I'm missing, but I cannot for the life of me figure out how to set the msg.value variable in this contract. I've read online that this value is the amount of wei associated with the transaction, but how do I, as a caller of the contract, specifically set that value. Here's the contract I'm struggling with.
pragma solidity 0.8.7;
contract VendingMachine {
// Declare state variables of the contract
address public owner;
mapping (address => uint) public cupcakeBalances;
// When 'VendingMachine' contract is deployed:
// 1. set the deploying address as the owner of the contract
// 2. set the deployed smart contract's cupcake balance to 100
constructor() {
owner = msg.sender;
cupcakeBalances[address(this)] = 100;
}
// Allow the owner to increase the smart contract's cupcake balance
function refill(uint amount) public {
require(msg.sender == owner, "Only the owner can refill.");
cupcakeBalances[address(this)] += amount;
}
// Allow anyone to purchase cupcakes
function purchase(uint amount) public payable {
require(msg.value >= amount * 1 ether, "You must pay at least 1 ETH per cupcake");
require(cupcakeBalances[address(this)] >= amount, "Not enough cupcakes in stock to complete this purchase");
cupcakeBalances[address(this)] -= amount;
cupcakeBalances[msg.sender] += amount;
}
}
Every time I enter an amount, I'm getting thrown the error that says "You must pay at least 1 ETH per cupcake"
There's nowhere for me to specifically enter in a value for how much I'm going to pay for this, any help would be great
here's what I'm able to input when I deploy the contract on Remix
Top of the Deploy Button you can see the Value Field :
when you want to call the purchase , first fill the value field and select Ether after that calls your function.
I try this way with your code and it works fine.

Solidity unit type holding an array?

I am working through the solidity course cryptozombies and heres something im not understanding
struct Zombie {
string name;
uint dna;
uint32 level;
uint32 readyTime;
uint16 winCount;
uint16 lossCount;
}
Zombie[] public zombies;
mapping (uint => address) public zombieToOwner;
mapping (address => uint) ownerZombieCount;
function _createZombie(string memory _name, uint _dna) internal {
uint id = zombies.push(Zombie(_name, _dna, 1, uint32(now + cooldownTime), 0, 0)) - 1;
zombieToOwner[id] = msg.sender;
ownerZombieCount[msg.sender]++;
emit NewZombie(id, _name, _dna);
}
Based on my understanding "zombies" is an array containing a string and different type of integers. If you look in the _createzombie function "id" is set as an uint. How can something of type uint store all these values?
Based on my understanding "zombies" is an array containing a string and different type of integers
This is only partially correct. zombies is in fact an array. But each of its items is of type Zombie.
A struct (docs) is kind of a "wrapper" type - it can contain multiple other datatypes on the inside, but from the outside it's seen as just one datatype (in this case you created a new datatype called Zombie).
You can see it for example in the push() function that accepts one new item of the array - type Zombie (wrapping the other variables).
zombies.push(
Zombie(...) // pushes 1 item of type `Zombie` to the array
)