Newbie Solidity Error/Question — 'ParserError: Expected identifier but got 'function'…' - syntax-error

function assessVoter () public view returns(uint) {
uint weight = (msg.sender).balance;
return (weight);
}
edit: I figured out the issue re: identifier. I had started a struct above and forgot to delete the incomplete struct. But assistance regarding the identification of balance would still be super appreciated!
I created a function to return the balance of a user's wallet address... Not sure if this is even how its properly done, just made intuitive sense to me ^ . ^
I got this error. Part of the issue is that I am very new and don't know what an identifier is. Additionally, as a side question, how would one query for the balance of a specific ERC-20 within a wallet?
ParserError: Expected identifier but got 'function' function assessVoter () public view returns(uint)

Welcome to Stack Overflow. Please look at community guidelines for posts. Include well formatted thoughts, clear and decise problems you are encountering and what you have tried compared with how it differs from what you are expecting.
ERC20 is a smart contract just like any other. Here is an example of how to call a method of another contract of the network. In this case - you would be calling the balance method of the token contract.
var contractABI = [{"constant":true,"inputs":....}];
var contractAddress = "0xa74476443119A942dE498590Fe1f24500000000";
var lookupAddress = "0xa74476443119A942dE498590Fe1f245000000000";
var contract = eth.contract(contractABI).at(contactAddress);
var balance = contract.balanceOf(lookupAddress);

Related

Using "ERC20" and interfaces names as variable (in functions)

I'm having problems wrapping my head around ERC20 and interfaces passed as variables.
Examples:
function foo(ERC20 _project) external { //some code }
function fuu(IERC4626 _project) external { ERC20(_project.asset()) }
What does this exactly do and how do we use it?
Haven't been able to find any explanation next to: Using interface name as Variable type. A link to the explanation is also fine.
My guesses:
Example 1: we input an address type which simply refers to an ERC20 contract, which we can use then as:
Project project = _project;
project.withdraw();
If above is true, why don't we simply take in an address type in the function instead of "ERC20" type?
Example 2: Calls an ERC20 contract which implements the IERC4626 interface? If so, how is that checked? tbh I have no idea.

*big.int and *types.transaction issues during interaction of solidity smart contract using Go-ethereum package

I want to interact solidity simple smart contract using Golang based Go-ethereum package, which showing me the error of *types.transaction and *big.int (returning these instead of string and uint) while functions are:
function Vote() public payable returns (string memory)
function Result() public view returns (uint)
My question is how can I manage them, so that I can get exactly the same value as required.
I think this is because transaction is being performed before this function call, which may be the cause.
By your guess, you have to wait for the transaction to be mined before you can see any resulting value of the transaction.
However, in your case the results are *types.Transaction and *big.Int, this indicates that you are using the deploy-time contract instance, or not initializing the deployed contract (need RPC connection).
You can refer section "Accessing an Ethereum contract" from here, hope you can find the answer

What is the purpose of symbol and name in ERC721?

I'm new to ERC721 and have some question on it.
I was following some tutorial and have question on constructor.
The question parts are below.
constructor(string memory baseURI) ERC721("NFT Collectible", "NFTC") {
setBaseURI(baseURI);
}
I understood what is memory but still don't know what is symbol and name in there.
Can I change it randomly?
What is the purpose of those?
And Where can I find that symbol and name?
That's my question.
I'm freshman in blockchain so some terms are unfamiliar.
So it will be great help if someone tells in details.
Yes, you can change it randomly. It does not matter if you have ERC20 or ERC721 token. Both of them need to have a name and a symbol. Let's say we have us dollar. So the name is "United States dollar" and symbol is "USD".
It is same for your tokens, you need to give them some name and symbol according to the ERC721 technical standard.
#dev Initializes the contract by setting a name and a symbol to the token collection.
// Token name
string private _name;
// Token symbol
string private _symbol;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
you can give your own token name and symbol
for more info you can read this openzeppelin doc
I do not know the purpose of name and symbol but I think that the purpose of ERC721 is to not effect on our nft that we posted on any nft platform example like opensea, Rarible etc. if some how nft marketplaces are hacked then it not be effected.

Solidity contract not working

I'm having trouble running my first solidity contract in remix ethereum and through web3 so I'm guessing something is wrong with my contract code:
pragma solidity ^0.4.0;
contract cntrct
{
uint public aaa;
function() payable public
{
create(msg.value);
}
function create(uint _value) internal
{
require(_value>0);
aaa = _value;
}
function reader() view public returns(uint)
{
return aaa;
}
}
I succesfully deployed the contract in both remix and web3. However, after sending a transaction to the contract, the aaa variable is still 0. What I want this code to do is update the aaa variable to the last deposited amount so I can read it later by calling the reader function. In remix it does not show any input field for the aaa variable. Also, in MetaMask transactions sent to the contract stay in a pending status even if they're already completed (balances updated in remix and tx in testRPC.)
In node I'm using the following line to try to execute the reader function but I'm unsure if this will work.
contract.methods.reader().call(0, (error, result) => { if(!error){console.log(result);}});
There’s no reason to store the ether sent in a state variable unless you need to maintain a mapping of balances spread across multiple addresses. The total balance is held in the contract and is accessible with this.balance.
In addition, fallback functions are limited to 2300 gas. You can’t write to storage (ie, update a state variable) within that limit. Your variable isn’t updated because it’s failing. See the second bullet point here for more info.
In solidity contract, you can read the value of public filed by calling field as a method. here, aaa()
I have deployed with mist browser under private network and send 10 ether to this contract successfully.

web3.js - how to check if a Token Contract implements ERC223 standard?

I would like to receive payments in any given ERC20 Token.
For that, the user must fisrt approve the transaction calling...
function approve(address, uint)
... on the Token's contract and then call to a specific function on MyContract that will triggers the actual transfer, calling...
function transferFrom(address from, address to, uint tokens)
... again on the Tokens's contract
That works fine but is very tedius and has double gas spending.
Now I found out the ERC223 standard that solves this (and other issues) but is not implemented by the mayority of the current popular tokens. It would be great to give the user the opportunity to pay just making a single transaccion when posible.
So, how can I dynamicaly check if a given token address implements ERC223 standar using web3 v0.x (im using v0.20.4) ?