I'm having a hard time understanding the documentation for making an external function call from one contract to another. In this tutorial there is an example:
contract InfoFeed {
function info() returns (uint ret) { return 42; }
}
contract Consumer {
InfoFeed feed;
function setFeed(address addr) { feed = InfoFeed(addr); }
function callFeed() { feed.info.value(10).gas(800)(); }
}
Which works when I run it from mist.
I am trying to write this contract:
contract Auditor is owned {
growId public grower_IDs;
mapping (address => bool) public approvedGrows;
function Auditor(address GID){
grower_IDs = growId(GID);
grower_IDs.transferOwenership(this);
}
function approveGrower(address target){
if (approvedGrows[target] == true) throw;
else approvedGrows[target] = true;
}
function issueGrowerID(address target) {
if (approvedGrows[target] == true && grower_IDs.balanceOf.value(10).gas(1000)(target) == 0) {
grower_IDs.makeID.value(10).gas(1000)(target);
}
else throw;
}
}
After you transfer ownership (full source included in the bottom) of the grower_ID contract to the Auditor you are able to approve an address, but I get an intrinsic gas is too low error if I try to issue an ID token. The problem is this line grower_IDs.makeID.value(10).gas(1000)(target);
, which is the same form as the example feed.info.value(10).gas(800)();
which does not get the error. Im not really understanding what the .value() is for when making this call. Is there a way to let is run it with an unspecified amount of gas?
Full source:
contract owned {
address public owner;
bool disabled;
function owned() {
owner = msg.sender;
disabled = false;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
}
modifier disableable {
if (disabled == true) throw;
}
function trasferOwnership(address newOwner) onlyOwner {
owner = newOwner;
}
event DisabledToggle(bool dis);
function disable() onlyOwner {
disabled = true;
DisabledToggle(true);
}
function enable() onlyOwner {
disabled = false;
DisabledToggle(false);
}
}
contract growId is owned {
string public name;
string public symbol;
uint8 public decimals;
mapping (address => uint256) public balanceOf;
function growId() {
name = "growId";
symbol = "GID";
decimals = 1;
}
function isOwner() returns (bool ret) {
if (msg.sender == owner) return true;
}
function makeID(address target) onlyOwner {
balanceOf[target] += 1;
Transfer(0, target, 1);
}
function transfer(address _to) disableable {
if (balanceOf[msg.sender] < 1 || balanceOf[_to] + 1 < balanceOf[_to])
throw;
if(msg.sender == owner){
balanceOf[msg.sender] -= 1;
balanceOf[_to] += 1;
Transfer(msg.sender, _to, 1);
}
if(_to == owner){
balanceOf[msg.sender] -= 1;
balanceOf[_to] += 1;
Transfer(msg.sender, _to, 1);
}
else throw;
}
event Transfer(address indexed from, address indexed to, uint256 value);
}
contract Auditor is owned {
growId public grower_IDs;
mapping (address => bool) public approvedGrows;
function Auditor(address GID){
grower_IDs = growId(GID);
grower_IDs.transferOwenership(this);
}
function approveGrower(address target){
if (approvedGrows[target] == true) throw;
else approvedGrows[target] = true;
}
function issueGrowerID(address target) {
if (approvedGrows[target] == true && grower_IDs.balanceOf.value(10).gas(1000)(target) == 0) {
grower_IDs.makeID.value(10).gas(1000)(target);
}
else throw;
}
}
Edit:
The procedure I've been trying is to first make the growId contract, then the auditor using the address of the growId. After I turn over ownership of the growId contract to the Auditors address, I add in one of my accounts as an approved grower. The error is when I try and use the auditor function issueGrowerID
. This function calls the growerID function grower_IDs.makeID(target)
. I have tried it with both grower_IDs.makeID(target)
and grower_IDs.value(x).gas(x)(target)
and it still says intrinsic gas too low.
.value()
is when you want to transfer wei: I don't think the Auditor wants to pay 10 wei each time it callsmakeID
. Try removing.gas()
since it limits the amount of gas available tomakeID
and this related information may help: ethereum.stackexchange.com/questions/551/…