Similar to How do you call a function of a deployed contract from another contract? (first answer), but because Truffle has access to the ABI's of compiled contracts thought I could avoid low-level call
Want to call a public function timeProtectTokens
on token
variable representing ERC20 contract within Escrow contract.
Intuitively I thought to do:
let token = await ERC20.new()
let escrow = await Escrow.new(token.address)
let result = await escrow.token.timeProtectTokens(initialAccount, 5)
..but fails
contract ERC20 is Protected {
}
import "./ERC20.sol";
contract Escrow {
ERC20 public token;
constructor(ERC20 _token) public {
token = _token;
}
}
contract Protected {
mapping (address => uint256) public protectedTokens;
function timeProtectTokens(address _address, uint256 _amount) public **onlyEscrow** {
protectedTokens[_address] = protectedTokens[_address].add(_amount);
}
}