What do you mean by accessing the functions? Do you mean executing the functions or changing the contract?
Got it!
Thanks a lot Filip! Appreciate the help
In token.sol at line 93: newOwner = address(0);
I do not understand the (0) ?
also, at line 204, what does allowed[msg.sender][spender] = tokens; means ?
I still do not understand a âdouble mappingâ ==> mapping(address => mapping(address => uint)) allowed; (line 109)
thank you,
Danny
address(0) is just the zero address. Meaning the address containing only zeros like this: 0x00000000âŚ00. If you are familiar with hexidecimal you know that 0 = 0x00000000âŚ00. So itâs just an address like any other. However, the way it is used can have special meaning. In the token contract, the zero address is used to âburnâ tokens. So all tokens that are sent to the zero address would be consider âburntâ and no longer in existance. You will find more about this if you google for âsolidity address 0â.
allowed[msg.sender][spender] is a 2 dimensional array. You can find more information about that generally here: https://processing.org/tutorials/2darray/. There are plenty of good explanations for 2d arrays in blog posts and youtube videos.
The double mapping is really nothing special. Normally you have a mapping that takes a key and points to a value. In a double mapping that value is not an integer or a string, instead itâs another mapping, that takes a new key and points to another value. In your example that value is an integer. If you still havenât grasped the concept, I would advice you to draw. Start by drawing how a normal mapping works, for example addresses pointing to integers.
After that you can attempt to draw the double mapping, where each address points to individual mappings instead.
I mean executing the functions.
As long as the contract is deployed to a blockchain and not only the VM you can access it from for example myetherwallet. All you need is the address and the ABI string. You can get those from within remix for example.
In the video he transfers 10 thousand tokens. To actually transfer 10 thousand tokens you need to type in this number â10000000000000000000000â since there are 18 decimals.
If you type in â10000â then you will get the followingâŚ
Question: what happens if the fundingGoalReached not reached function is triggered and the funds are transferred back to the sender and after a few transfers you run out of gas. What happens in that case?
Is there a way one can check if a wallet is able to receive ERC20 tokens? Often it happens, that people send ETH from their (for example) Binance account which should be rejected by the contract to avoid unnecessary support issues.
Hi Filip,
In the token.sol contract, in the constructor, the Transfer event has three arguments, address(0), our MEW address, and _totalSupply). What is address(0), is that a specific address? I think it appearing elsewhere within the contract. For example the function for total supply returns _totalSupply - balances[address(0)].
Update: I found the answer, so itâs ok! For anyone interested, hereâs the link which I got the information from:
https://medium.com/@jgm.orinoco/understanding-erc-20-token-contracts-a809a7310aa5
Hi Hiro and Filip,
I was looking through Crowdsale Part 2, and in the video when Filip was writing the code for safeWithrdrawal()
, I noticed that we were supposed to type msg.sender.send(amount) (timestamp in the video is 17:45).
Subsequently, we needed to check if the transfer failed or not, using an if statement. However, after writing that in, we did not include the actual sending of the funds. We only input code for âif it failsâ, but if the transfer is successful, I donât see any code for such an action. Could that be where the problem lies?
On that note, I am a bit with that portion. for the lines
if(!msg.sender.send(amount)){
balanceOf[msg.sender] = amount;
}
}
}
if(fundingGoalReached && msg.sender == beneficiary){
if(!beneficiary.send(totalAmountRaised)){
fundingGoalReached = false;
Can transfers be executed within the if statement? Because within this function, msg.sender.send(amount) and beneficiary.send(totalAmountRaised) only appear in the if statement condition, and no where else in the function. Does that mean that they were executed, and then assessed as true or false, all within the if statement itself?
Good question. The funds are not transferred back automatically if the crowdsale fails. Every contributor needs to call the safeWithdrawal function themselves to withdraw their own funds. So we donât have that issue with gas running out.
No, not through programming in the contract. The best solution atm is to simply ask the user what wallet they are using and only accepting eth if the user has a EIP-20 wallet.
I believe the ERC223 token standard solves a big part of these issues since it doesnât allow transfers to contracts that doesnât support the token.
Well, in the beginning of that function we set the balance of the msg.sender to 0. So if the transfer succeeds we donât need to do anything else. If it fails however, we need to reset the balance to what it previously was. Since no successfull transfer actually took place. I hope I answered your question. Take a look at the entire function once again and let me know if you need more help.
Dear Filip,
I have some questions and issues I canât seem to understand/solve:
-
as apeondrums asked, in the safeWithdrawal function there is no âsendâ command, only the checking, wether the amount went through correctly. But, since there is no sending command, how does it check, wether it went through?
-
what is the unit of the msg.value? Is it ETH, WEI, or FilipCoin?
-
How is the fundingGoalReached will be set to true? This is only set by the function checkGoalReached, but what fires off this function? nothing calls it.
-
Do I understand correctly, that the constructor function Crowdsale gets fired immediately at the deployment, therefore When we are setting the crowdSaleDeadline = now + âŚ; the ânowâ value will be equal to the timestamp of the deploy?
-
I tried to send tokens to the crowdsale address, however, the transaction reverted: https://rinkeby.etherscan.io/tx/0x1aa330be5368ea7cce91aa84efef3df3c71585d679c32f214372030fcbdd29a3
Just for clarification, is my following understanding correct?:
I have created a new (second) account on MEW and sent some ETH from my (first) MetaMask account to it. Also, In the FilipCoin contract it is defined, that this second MEW adress has the totalsupply of the FilipCoin. But, I can interact with these tokens on my account only through the contract and that is why I have to send the tokens to the crowdsale contract through the Interaction with the Contract.
So I go to the contracts on myetherwallet and paste in the filipcoin contractâs address. Then go to the compile tab in Remix and copy the details of the filipcoin contract to the ABI interface. Select transfer and paste in the crowdsaleâs address. I put in how much token I want to transfer (I have tried with both 10000 and 10e22 amount). It sends the transaction, but it doesnât go through. Where could be the problem? I have defined the same parameters as you have with (my own Metamask Address,10,100,1,FilipCoin contract Address).
And a general comment, for a little more clarification:
It would be great, if the different types and variables would have unique naming. E.g. donât name the contract, the token, the symbol and itâs name all FilipCoin, so it is always clear, which one is used
Good questions.
-
Yes there is. On line 87. Here is where we first send the amount though the send() function. Then we check the result in the if statement, all in the same line.
if(!msg.sender.send(amount)){
-
Wei
-
Anyone can call that function after the deadline has ended. You, me, the owner of the crowdsale, any investor can call it. Itâs not done automatically though.
-
Yes, correct. The now variable is defined in the solidity language as the current timestamp.
-
Yes thatâs corrent. Iâm not sure why your transaction failed. Itâs very difficult to know whatâs going on, something is probably wrong in your contract or in how you interact with it. But Iâm not sure.It could depend on a lot. Is it still not working for you?
In the airdrop video, we look at an alternative way to handle to tokens back and forth. You will probably get a better understanding after that.
Hello Flip,
I am really enjoying the course - thank you and to Ivan.
I am confused by the following line in the constructor.
Transfer(address(0), 0x49894CA8df470d5e0448A602373EdE1780AA4450, _totalSupply);
I cannot see what this does. I have read up on the special case 0x address. To me teh above line looks like transferring the entire balance to the 0 or spent pool ?
Many thanks
Paul.
Hi Paul,
Thatâs a good question. I was kind of confused by that too when I looked at it. I should have covered it in the video maybe⌠Either way, that line calls the Transfer event, not the Transfer function. You know that by looking at the arguments, it has 3 arguments while the Transfer function only has 2.
What that does is that it makes it clear from the start which address holds all the tokens by emitting an event. The event says that the entire balance has been transferred FROM address zero to 0x49894CA8df470d5e0448A602373EdE1780AA4450.
Was my explanation clear enough?
Hi Filip,
Many thanks - i see this distinction now. It is not a transfer but a notification of creation/initial transfer event.
many thanks,
Paul