In Remix, I'm getting the following error.
contracts/TestBench.sol:138:30:
TypeError: Data location must be "calldata" for parameter
in external function, but none was given.
function updateTokenName(string _name) external onlyOwner {
^----------^
That error references the below line of code (full smart contract is appended at the bottom).
function updateTokenName(string _name) external onlyOwner {
Then, after replacing the above problematic line with the following line like this:
function updateTokenName(string calldata _name) external onlyOwner {
I get a series of new errors that look like this. They all reference previous lines of code that passed the compiler without errors before I made the "fix" by adding calldata
.
contracts/TestBench.sol:52:9:
DeclarationError: Undeclared identifier.
allowed[msg.sender][_spender] = _tokens; / ...
^-----^
The full function that error references is as follows.
function approve(address _spender, uint256 _tokens) external {
allowed[msg.sender][_spender] = _tokens; // Allow spender to withdraw from msg.sender's account multiple times, up to the specified amount of tokens.
}
What am I doing wrong and how can I fix these errors? What is the proper way to declare the identifiers the error message is referencing?
Full smart contract
pragma solidity ^0.5.0;
contract FractionalizedAssets {
address public owner; // contract creator
mapping (address => uint) public tokenBalanceOf; // map of address and token balance
constructor() public {
owner = msg.sender;
}
function mint(uint256 _amount, address _to) external onlyOwner {
require(_amount > 0);
tokenBalanceOf[_to] += _amount; // Increase the token balance for user's account by specified amount.
}
function transfer(address _from, address _to, uint256 _tokens) external { // Allow users to trade tokens between each other
require(tokenBalanceOf[_from] >=_tokens && _tokens > 0); // Ensure that sender has enough tokens to send
tokenBalanceOf[_from] -=_tokens; // Substract tokens from sender's account
tokenBalanceOf[_to] +=_tokens; // Add tokens to receiver's account
emit Transfer(_from,_to,_tokens); // Notify listeners about transfer event
}
event Transfer(address indexed from, address indexed to, uint256 value);
modifier onlyOwner() {
require( msg.sender == owner );
_;
}
function burn(uint256 _amount, address _from) external onlyOwner {
require(_amount > 0);
tokenBalanceOf[_from] -= _amount; // Decrease the token balance for user's account by specified amount.
}
function totalSupply() public view returns (uint256) {
return address(this).balance; // Return the total supply of tokens in circulation.
}
function balanceOf(address _owner) public view returns (uint256) {
return tokenBalanceOf[_owner]; // Return the token balance of specified address.
}
function transferFrom(address _from, address _to, uint256 _tokens) external {
require(_tokens > 0 && tokenBalanceOf[_from] >=_tokens); // Ensure that sender has enough tokens to send
tokenBalanceOf[_from] -=_tokens; // Substract tokens from sender's account
tokenBalanceOf[_to] +=_tokens; // Add tokens to receiver's account
emit Transfer(_from,_to,_tokens); // Notify listeners about transfer event
}
function approve(address _spender, uint256 _tokens) external {
allowed[msg.sender][_spender] = _tokens; // Allow spender to withdraw from msg.sender's account multiple times, up to the specified amount of tokens.
}
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender]; // Return the remaining number of tokens that spender is still allowed to withdraw from owner's account.
}
function transferFrom(address _from, address _to, uint256 _tokens) external {
require(_tokens > 0 && tokenBalanceOf[_from] >=_tokens && allowed[_from][msg.sender] >=_tokens); // Ensure that sender has enough tokens to send
tokenBalanceOf[_from] -= _tokens; // Substract tokens from sender's account
tokenBalanceOf[_to] += _tokens; // Add tokens to receiver's account
allowed[_from][msg.sender] -= _tokens; // Decrease the amount of remaining tokens spender is still allowed to withdraw from owner's account
emit Transfer(_from,_to,_tokens); // Notify listeners about transfer event
}
function increaseApproval(address _spender, uint256 _addedValue) external {
allowed[msg.sender][_spender] += _addedValue; // Increase the amount of tokens that spender is still allowed to withdraw from owner's account.
}
function decreaseApproval(address _spender, uint256 _subtractedValue) external {
allowed[msg.sender][_spender] -= _subtractedValue; // Decrease the amount of tokens that spender is still allowed to withdraw from owner's account.
}
function burnFrom(address _from, uint256 _tokens) external {
require(_tokens > 0 && tokenBalanceOf[_from] >=_tokens && allowed[_from][msg.sender] >=_tokens); // Ensure that sender has enough tokens to send
tokenBalanceOf[_from] -=_tokens; // Substract tokens from sender's account
allowed[_from][msg.sender]-=_tokens; // Decrease the amount of remaining tokens spender is still allowed to withdraw from owner's account
emit Burn(_from,_to,_tokens); // Notify listeners about transfer event
}
event Burn(address indexed from, address indexed to, uint256 value);
function burnAll(address _from) external onlyOwner {
uint256 balance = tokenBalanceOf[_from]; // Get the user's current token balance.
require(balance > 0); // Ensure that user has tokens to burn.
tokenBalanceOf[_from] = 0; // Set the user's token balance to zero.
emit Burn(_from, address(0), balance); // Notify listeners about transfer event.
}
function pause() external onlyOwner {
paused = true; // Set the contract to a paused state.
emit Pause(); // Notify listeners about transfer event.
}
function unpause() external onlyOwner {
paused = false; // Set the contract to an unpaused state.
}
event Pause();
function renounceOwnership() external onlyOwner {
emit OwnershipRenounced(owner); // Notify listeners about transfer event.
owner = address(0); // Set the contract's owner to zero.
}
event OwnershipRenounced(address indexed previousOwner);
function transferOwnership(address _newOwner) external onlyOwner {
require(_newOwner != address(0)); // Ensure that new owner is not zero.
emit OwnershipTransferred(owner, _newOwner); // Notify listeners about transfer event.
owner = _newOwner; // Set the contract's owner to the new owner.
}
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function reclaimEther() external onlyOwner {
owner.transfer(address(this).balance); // Transfer all ether in the contract to the owner's address.
emit ReclaimEther(); // Notify listeners about transfer event.
}
event ReclaimEther();
function destroy() external onlyOwner {
selfdestruct(owner); // Destroy the contract and transfer all ether in the contract to the owner's address.
emit Destroy(); // Notify listeners about transfer event.
}
event Destroy();
function updateOwner(address _newOwner) external onlyOwner {
require(_newOwner != address(0)); // Ensure that new owner is not zero.
emit OwnershipTransferred(owner, _newOwner); // Notify listeners about transfer event.
owner = _newOwner; // Set the contract's owner to the new owner.
}
function updateTokenName(string calldata _name) external onlyOwner {
tokenName = _name; // Update the name of the token.
emit TokenNameUpdated(_name); // Notify listeners about transfer event.
}
event TokenNameUpdated(string indexed newTokenName);
}