Error in the implementation of Solidity code - solidity

Hi I ran the following code but unfortunately I got this error at run time
ParserError: Expected ';' but got reserved keyword 'in'
--> Reputation.sol:90:30:
|
90 | for (address rater in reputation[seller]){
| ^^
Please help, thank you
`
function rateSeller(address seller, address rater, uint rating) public {
reputation[seller][rater] = rating;
uint reputationSum = 0;
uint numRatings = 0;
uint reputationAverage=0;
for (address rater in reputation[seller]){
reputationSum += reputation[seller][rater];
numRatings++;
}
reputationAverage=reputationSum / numRatings;
return reputationAverage;
}`
I want to calculate the reputation given to each seller for a specific rater. In fact, the collection of all sellers evaluated by a particular evaluator. Please guide. Thank you

Your for() loop syntax is wrong. To edit properly i need more source code. But it should be something like this:
for(uint index; index < arrayName.length; index++) {
your code
}

First of all i added productId variable, that counter product ids. Also changed mapping reputation, now it just sum up sellers reputation. With this approach its way easier to check sellers reputation.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Marketplace {
address payable public owner;
mapping(address => bool) public sellers;
mapping(uint => Product) public products;
mapping(address => mapping(uint => bool)) public purchased;
mapping(address => mapping(uint => bool)) public disputes;
mapping(address => mapping(uint => bytes32)) public reviews;
mapping(address => uint) public reputation;
uint public productId;
struct Product {
address payable seller;
uint price;
string name;
string description;
}
event ProductListed(uint productId);
event ProductPurchased(uint productId);
event DisputeRaised(uint productId);
event DisputeResolved(uint productId);
constructor() {
owner = payable(msg.sender);
}
function addSeller(address seller) public {
require(msg.sender == owner);
sellers[seller] = true;
}
function removeSeller(address seller) public {
require(msg.sender == owner);
sellers[seller] = false;
}
function listProduct(
address payable seller,
uint price,
string memory name,
string memory description) public {
(sellers[seller]);
products[productId] = Product(seller, price, name, description);
productId++;
emit ProductListed(productId);
}
function purchaseProduct(uint _productId, address buyer) public payable {
require(products[_productId].price <= msg.value);
require(!purchased[buyer][_productId]);
products[_productId].seller.transfer(products[_productId].price);
purchased[buyer][_productId] = true;
emit ProductPurchased(_productId);
}
function raiseDispute(uint _productId, address buyer) public {
require(purchased[buyer][_productId]);
disputes[buyer][_productId] = true;
emit DisputeRaised(_productId);
}
function resolveDispute(uint _productId, address payable buyer, bool refund)
public {
require(msg.sender == owner);
require(disputes[buyer][productId]);
if (refund) {
buyer.transfer(products[_productId].price);
}
disputes[buyer][_productId] = false;
emit DisputeResolved(productId);
}
function leaveReview(uint _productId, address buyer, bytes32 review) public {
require(purchased[buyer][_productId]);
reviews[buyer][_productId] = review;
}
function rateSeller(address seller, uint rating) public {
reputation[seller] += rating;
// reputation[seller][rater] = rating;
}
function getProduct(uint _productId) public view returns (address payable, uint,
string memory, string memory) {
return (products[_productId].seller, products[_productId].price,
products[_productId].name, products[_productId].description);
}
function getSellerReputation(address seller) public view returns (uint) {
return reputation[seller];
}
}

Related

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" }
I have implemented the safemoon contract but when I deployed the code in the BSC testnet it's given me an error.
contract SafemoonDemo is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private _isExcluded;
address[] private _excluded;
uint256 private constant MAX = ~uint256(0);
uint256 private _tTotal = 1000 * 10**6 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 private _tFeeTotal;
string private _name = "SafeMoonDemo";
string private _symbol = "SFD";
uint8 private _decimals = 9;
uint256 public _taxFee = 5;
uint256 private _previousTaxFee = _taxFee;
uint256 public _liquidityFee = 5;
uint256 private _previousLiquidityFee = _liquidityFee;
IUniswapV2Router02 public immutable uniswapV2Router;
address public immutable uniswapV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = true;
uint256 public _maxTxAmount = 5000 * 10**6 * 10**9;
uint256 private numTokensSellToAddToLiquidity = 5000 * 10**6 * 10**9;
event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiqudity
);
modifier lockTheSwap {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor () public {
_rOwned[_msgSender()] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
// Create a uniswap pair for this new token
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
// set the rest of the contract variables
uniswapV2Router = _uniswapV2Router;
//exclude owner and this contract from fee
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
Your constructor is trying to call the factory() function on the 0x10ED43C718714eb63d5aA57B78B54704E256024E address, expecting a 20-byte response that it would convert to an address type.
Even though there is the PancakeSwap router contract deployed on this address on the BSC mainnet, the BSC testnet doesn't hold any contract on this address.
So your constructor fails as it doesn't get the 20-byte response (from the non-contract address) that it expects.
The Pancakeswap docs page doesn't list any testnet addresses, so it's possible that there are no official Pancakeswap contracts on the testnet.

How can I reveal NFTs as they are minted?

My goal is to get my reveal function to only reveal the NFT as it gets bought/minted and not reveal the whole collection so that people don't have to wait, however I just keep mucking it up.
Here is what I've got
string baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.05 ether;
uint256 public maxSupply = 10000;
uint256 public maxMintAmount = 20;
bool public paused = true;
bool public revealed = false;
string public notRevealedUri;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
uint256 public nftPerAddressLimit = 100;
mapping(uint256 => string) private _tokenURI;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
now for the reveal
function reveal() public onlyOwner {
revealed = false;
}
I can't seem to think of a way that would change the bool for specific tokens as they get minted.
My thought was that it should be at the end of the mint function itself, though I am not at all confident in that.
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
_tokenURI[supply].revealed = true; <-- *I know this wont work if anyone ever mints more than one at a time.*
}
You can include a mapping to hold the reveal states of your nfts. I am not sure whether you intended only admin to call this reveal function every time, in this case this would do!
....
mapping(address => mapping(uint256 => bool)) private reveals;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
function reveal(address _nftContract, uint256 tokenId, bool _reveal) external onlyOwner {
bool revealed = reveals[_nftContract][tokenId];
require(!revealed, 'Token Already revealed');
reveals[_nftContract][tokenId] = true;
}
The best method of doing what I asked, is in fact to not mint any yourself, and have a D-app on a website so that total supply is only that of what has been minted, thus can only point to the baseURI then

DeclarationError: Undeclared identifier. Did you mean "balanceOf" or "blances"?

I am trying to create my own token using Solidity on Remix Ethereum. I use MetaMask and logged in Binance Smart Chain Testnet . But when I use Solidity Compiler to compile, it keeps showing this error on lines 15, 19, 24, 25, 33, 34:
DeclarationError: Undeclared identifier. Did you mean "balanceOf" or "blances"?
Here the code:
pragma solidity ^0.8.2;
contract MyTestToken {
mapping(address => uint) public blances;
mapping(address => mapping(address => uint)) public allowance;
uint public totalSupply = 1000000000000 * 10 ** 18;
string public name = "MyToken Test";
string public symbol = "TKNT";
uint public decimals = 18;
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
constructor () {
balances[msg.sender] = totalSupply;
}
function balanceOf(address owner) public view returns(uint) {
return balances[owner];
}
function transfer(address to, uint value) public returns(bool) {
require(balanceOf(msg.sender) >= value, 'balance too low');
balances[to] += value;
balances[msg.sender] -= value;
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint value) public returns(bool) {
require(balanceOf(from) >= value, 'balance too low');
require(allowance[from][msg.sender] >= value, 'allowance too low');
balances[to] += value;
balances[from] -= value;
emit Transfer(from, to, value);
return true;
}
function approve(address spender, uint value) public returns(bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
}
Thank you in advance.
It's caused by a typo in your code. Rename the mapping blances to balances.
mapping(address => uint) public blances; // original code
mapping(address => uint) public balances; // corrected

How would I implement a buy/sell transfer tax within solidity

I want to put a transfer tax into my code but not sure how to go about it. I would apply a 2.5% tax on buys and sells. Any help/advice would be greatly appreciated. This is what I have so far:
pragma solidity ^0.8.4;
contract Token {
mapping(address => uint) public balances;
mapping(address => mapping(address => uint)) public allowance;
uint public totalSupply = 100000000000 * 10 ** 18;
string public name = "*****";
string public symbol = "****";
uint public decimals = 18;
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
constructor(){
balances[msg.sender] = totalSupply;
}
function balanceOf(address owner) public view returns(uint){
return balances[owner];
}
function transfer(address to, uint value) public return(bool){
require(balanceOf(msg.sender) >= value, 'balance too low');
balances[to] += value;
balances[msg.sender] -= value;
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint value) public returns(true){
require(balanceOf(from) >= value, 'balance too low');
require(allowance[from][msg.sender] >= value, 'allowance too low');
balances[to] +=value;
balances[from] -= value;
emit Transfer (from, to, value);
return true
}
function approve (address spender, uint value) public reutrns(bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
}

Whant's wrong is my erc20 token deploy in solidity remix ide

Here is my ERC20 implementation code. When I deploy to Ropsten testing network, I can't add token to my metamask by demonstrating token symbol automatically. I still can't send it to the other account in MEW wallet by error message. All of the function in contract follow the erc20 interface.
contract TWTD {
mapping (address => uint256) public ownerTobalance;
mapping (address => mapping (address => uint256)) public allowance;
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
string TokenName;
string Symbol;
uint8 decimals = 18;
uint256 totalsupply;
using SafeMath for uint256;
function TWTD(string _name, string _symbol, uint256 _initialsupply) public {
ownerTobalance[msg.sender] = _initialsupply;
totalsupply = _initialsupply;
TokenName = _name;
Symbol = _symbol;
}
function totalSupply() public view returns (uint256){
return totalsupply;
}
function balanceOf(address who) public view returns (uint256) {
return ownerTobalance[who];
}
function _transfer(address from, address to, uint256 value) internal {
require ( to != 0x0);
require (ownerTobalance[from] >= value);
uint256 Balance = ownerTobalance[from] + ownerTobalance[to];
ownerTobalance[from].sub(value);
ownerTobalance[to].add(value);
assert(ownerTobalance[from] + ownerTobalance[to] == Balance);
emit Transfer(from,to,value);
}
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender,to,value);
return true;
}
function transferFrom(address from, address to, uint256 value) public returns (bool) {
require (allowance[from][msg.sender] >= value);
allowance[from][msg.sender].sub(value);
_transfer(from,to,value);
return true;
}
function approve(address spender, uint256 value) public returns (bool) {
require(value > 0);
allowance[msg.sender][spender] = value;
emit Approval(msg.sender,spender,value);
return true;
}
function allowance(address owner, address spender)
public view returns (uint256) {
return allowance[owner][spender];
}
}