I am a novice to Solidity so you will have to bear with me regarding the following question:
I am trying to compile my first smart contract and keep on running into this Declaration issue. How do I correctly declare an address variable in Solidity?
Find below my simple code:
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Owner
* @dev Set & change owner
*/
contract Gifter {
address private gifter;
//address private giftRecipient;
// event for EVM logging
event OwnerSet(address indexed gifter, address indexed giftRecipient);
// modifier to check if caller is owner
modifier isGifter() {
require(msg.sender == gifter, "Gift NOT yours to give away!");
_;
}
/**
* @dev Set contract deployer as owner
*/
constructor() {
gifter = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
emit OwnerSet(address(0), gifter);
}
/**
* @dev Change owner
*/
function giftTo( address giftRecipient ) public isGifter {
emit OwnerSet(gifter, giftRecipient);
//gifter = giftRecipient;
giftRecipient = giftRecipient;
}
/**
* @dev Return owner address
* @return address of owner
*/
function whoWasGifted() external view returns (address) {
return giftRecipient;
}
}
I keep getting the following error message:
DeclarationError: Undeclared identifier.
--> contracts/gifter.sol:45:16
|
45 | return giftRecipient;
| ^