tokenRecipient spender = tokenRecipient(_spender);
means "take the _spender
variable (which is an address
value that the transaction sender input) and cast it to a tokenRecipient
contract class (meaning, assume that whatever destination address the user is wanting me to use, assume that it meets the interface defined as tokenRecipient
)" That make sense?
approve
. If the other contract you're giving an allowance to is another smart contract, and it has implemented a receiveApproval
function (to let it do some logic immediately after receiving some tokens), use the approveAndCall
function to trigger that all in the same transaction call.
@MidnightLightning
When a contract is defined in Solidity like the
tokenRecipient
one in that contract, it acts kind of like what an "interface" would be in other languages.
Ok, but i'm confusing...so in that tutorial, should be corrected from
contract tokenRecipient { function receiveApproval(address from, uint256 value, address token, bytes extraData); }
to
interface tokenRecipient { function receiveApproval(address from, uint256 value, address token, bytes extraData); }
right ???
@MidnightLightning
Anyway, with contract keyword it works.
But for complete understanding the tutorial, i need to know this:
Should i deploy only the MyAdvancedToken contract (using truffle)?
Should i call the deployer link also or i don't to link?
This is my migration code:
var owned = artifacts.require("Owned");
var Token = artifacts.require("Token");
var TestCoin = artifacts.require("TestCoin");
module.exports = function(deployer) {
deployer.deploy(owned);
deployer.deploy(Token,1000000,'TestCoin',0,'TEC');
deployer.link(Token, TestCoin);
deployer.link(owned, TestCoin);
deployer.deploy(TestCoin);
};
Thank you very much for help me!
MyAdvancedToken
contract for basic functionality. If you want to test the approveAndCall
functionality, you'd need to deploy a second contract that implements that one receiveApproval
method.
pragma
command to be the version you have.