I have the code here -
pragma solidity ^0.4.18;
contract CollegeAdmin {
uint8 public studentAge=21;
uint16 public studentIncome=15000;
uint8 public studentScore=4;
uint8 public studentAttendance=96;
address public buyer;
address public owner;
event changedAge(uint age);
function CollegeAdmin() public {
owner = msg.sender;
}
function setAge(uint8 age) public {
buyer=msg.sender;
studentAge = age;
changedAge(age);
}
}
I deployed the contract using eth.coinbase and with eth.defaultAccount set.
Here is the output after deployment -
> con.buyer()
"0x"
> con.owner()
"0x"
>
con is the contract instance - eth.contract(abi).at(addr).
When is owner set? I thought it was set at deployment or when an instance is taken of the contract. Apparently not.
If the design is to set owner to ensure security in running the contract then when is that set? It seems to me it should be at the point of creation of the contract.
Here is the deployment -
con=eth.contract(abi).at(addr)
{
abi: [{
constant: true,
inputs: [],
name: "studentIncome",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: false,
inputs: [{...}],
name: "setAge",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: true,
inputs: [],
name: "buyer",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: true,
inputs: [],
name: "owner",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: true,
inputs: [],
name: "studentAttendance",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: true,
inputs: [],
name: "studentAge",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: true,
inputs: [],
name: "studentScore",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
inputs: [],
payable: false,
stateMutability: "nonpayable",
type: "constructor"
}, {
anonymous: false,
inputs: [{...}],
name: "changedAge",
type: "event"
}],
address: "0x438a135dc2d5466039c777d2bc59eeeb6b8f89c1",
transactionHash: null,
allEvents: function(),
buyer: function(),
changedAge: function(),
owner: function(),
setAge: function(),
studentAge: function(),
studentAttendance: function(),
studentIncome: function(),
studentScore: function()
}
> con.buyer
function()
> con.buyer()
"0x"
> con.owner()
"0x"
> con.address
"0x438a135dc2d5466039c777d2bc59eeeb6b8f89c1"
root@ubuntu-s-1vcpu-1gb-lon1-01:/geth/mybc/geth/zt/contracts# truffle migrate --reset
Compiling ./contracts/CAStorage.sol...
Writing artifacts to ./build/contracts
Using network 'development'.
Running migration: 1_initial_migration.js
Replacing Migrations...
... 0x9804c03cc3a84417d8954fb54f3c874f44785400519f02d1ca48e96a0fe2a524
Migrations: 0x28d9e2a0972fd59866581c1535b0bd1c447860d9
Saving successful migration to network...
... 0x7b0f04340c52e0ec55de27775ca205f3fd8e4bff718ca1353cba3c877f6799a0
Saving artifacts...
Running migration: 2_deploy_contracts.js
Replacing CollegeAdmin...
... 0x6463e8e73e21373fa2611883896b9881576f5b1f6791ec95b3dd47ec17fba6bf
CollegeAdmin: 0x438a135dc2d5466039c777d2bc59eeeb6b8f89c1
Saving successful migration to network...
... 0x1d3df599b04b8447913fc06bb00e37cfa6e9f1d5ac5fd8912d2f5c18da0aa689
Saving artifacts...
root@ubuntu-s-1vcpu-1gb-lon1-01:/geth/mybc/geth/zt/contracts# solc --bin --abi CollegeAdmin.sol
Warning: This is a pre-release compiler version, please do not use it in production.
======= CollegeAdmin.sol:CollegeAdmin =======
Binary:
606060405260156000806101000a81548160ff021916908360ff160217905550613a98600060016101000a81548161ffff021916908361ffff1602179055506004600060036101000a81548160ff021916908360ff1602179055506060600060046101000a81548160ff021916908360ff160217905550341561008157600080fd5b33600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610372806100d16000396000f300606060405260043610610083576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806311bc0d07146100885780635b0c8d70146100b95780637150d8ae146100df5780638da5cb5b14610134578063a0a628d614610189578063a918b856146101b8578063f4ea2d99146101e7575b600080fd5b341561009357600080fd5b61009b610216565b604051808261ffff1661ffff16815260200191505060405180910390f35b34156100c457600080fd5b6100dd600480803560ff1690602001909190505061022a565b005b34156100ea57600080fd5b6100f26102c2565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561013f57600080fd5b6101476102e8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561019457600080fd5b61019c61030e565b604051808260ff1660ff16815260200191505060405180910390f35b34156101c357600080fd5b6101cb610321565b604051808260ff1660ff16815260200191505060405180910390f35b34156101f257600080fd5b6101fa610333565b604051808260ff1660ff16815260200191505060405180910390f35b600060019054906101000a900461ffff1681565b33600060056101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550806000806101000a81548160ff021916908360ff1602179055507f25d30a71a6b93533225c97277375c3d49d3451741fad4852f106d04a5f083b5a81604051808260ff16815260200191505060405180910390a150565b600060059054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600060049054906101000a900460ff1681565b6000809054906101000a900460ff1681565b600060039054906101000a900460ff16815600a165627a7a7230582054a9b41a66fdc2a697455eb8fb25e95227c80fce8e350c939a47d2c4e82942030029
Contract JSON ABI
[{"constant":true,"inputs":[],"name":"studentIncome","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"age","type":"uint8"}],"name":"setAge","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"buyer","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"studentAttendance","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"studentAge","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"studentScore","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"age","type":"uint256"}],"name":"changedAge","type":"event"}]
I did more testing - and the issue is msg.sender. I just tested con.setAge(78) and that works. So the contract is working but the msg.sender is not working - it is finding 0x for msg.sender. This must be a truffle issue I assume.
Here is the truffle code -
root@ubuntu-s-1vcpu-1gb-lon1-01:/geth/mybc/geth/zt# more truffle.js
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*",
gas: 4712388
}
}
};
Here is the geth connection code -
root@ubuntu-s-1vcpu-1gb-lon1-01:/geth/mybc/geth# more gethlogin.sh
geth --datadir /geth/mybc --unlock "0x46fb9a22689c4a4bfb494baeafbb8b2993725305" --rpc --rpcaddr "localhost" --rpcport 85
45 --networkid 1234 --rpcapi "admin,db,eth,debug,miner,shh,txpool,net,web3,personal" --verbosity 5 console 2> console.lo
g