I am writing a simple contract which is basically a registry. I am using testRPC for my ethereum testing. Following is my contract on Truffle:
notary.sol
pragma solidity ^0.4.11;
contract notary {
struct individual {
bytes32 firstname;
bytes32 lastname;
uint yob;
bytes32 pancard;
uint aadhar;
}
mapping(address => individual) public user;
function Register(address _to, bytes32 _firstname, bytes32 _lastname, uint _yob, bytes32 _pancard, uint _aadhar) returns (bool success) {
if (user[_to].aadhar != 0) {
return false;
}
user[_to].firstname = _firstname;
user[_to].lastname = _lastname;
user[_to].yob = _yob;
user[_to].pancard = _pancard;
user[_to].aadhar = _aadhar;
return true;
}
function getDetails(address _to) constant returns (bytes32 _firstname, bytes32 _lastname, uint _yob, bytes32 _pancard, uint _aadhar) {
return (user[_to].firstname, user[_to].lastname, user[_to].yob, user[_to].pancard, user[_to].aadhar);
}
}
When I have deployed the contract using truffle compile and truffle migrate --reset
everything is working as intended. I have already registered one entry on the contract:
Action through console
> notary.deployed().then(function(instance) {NOTR = notary.deployed.at(instance.address)})
> NOTR.Register(web3.eth.accounts[9], 'mukesh', 'kumar', 1987, 'fbjsdkfd67', 324234)
> NOTR.getDetails(web3.eth.accounts[9])
[ '0x6d756b6573680000000000000000000000000000000000000000000000000000',
'0x6b756d6172000000000000000000000000000000000000000000000000000000',
{ [String: '1987'] s: 1, e: 3, c: [ 1987 ] },
'0x66626a73646b6664363700000000000000000000000000000000000000000000',
{ [String: '324234'] s: 1, e: 5, c: [ 324234 ] } ]
Now, next I am trying to have this with React as an interface. My React code is longer than I would want to put in here. Mainly, the interface is simply like the below:
Basically, as I click Submit I want to create a new registration. I have declared ABI, Contract Address and other parameters as required in my React App, in addition to all proper import etc. as required therein. In fact the following actually work on my React interface:
handleSubmit(event) {
// alert(notaryContract.getDetails(ETHEREUM_CLIENT.eth.accounts[9]))
// alert(JSON.stringify(this.state))
// alert(ETHEREUM_CLIENT.isAddress(ETHEREUM_CLIENT.eth.accounts[0]))
But as soon as I try notaryContract.Register('0xcc82fa55789663402c013a497eac268172af7f9d', this.state.setFirstName, this.state.setLastName, this.state.setYearofBirth, this.state.setPanCard, this.state.setAadhar)
it gives me an error as following (the _to
address included is one of the testrpc ones:
Uncaught Error: invalid address
at inputAddressFormatter (http://localhost:3000/static/js/bundle.js:59056:11)
at inputTransactionFormatter (http://localhost:3000/static/js/bundle.js:34345:27)
...long list...
at dispatchEvent (http://localhost:3000/static/js/bundle.js:31505:20)
Apologies for a long question but I am sure I am missing something minor here and I had to add in step by step reproduction to allow others to point out the problem. I have tried entering address in string form, then also simply using web3.eth.accounts[x]
for including the [_to]
address, but to no avail. I am thinking possibly because getDetails
is a constant function it is working since it does not expend any gas whereas Register
doesn't creates a transaction and cause a state change. However, I can't seem to fathom why it works in truffle console
whereas it doesn't in React app. I have checked the bundle.js from where invalid address error is coming from but given that there are no proper debugging logs yet to understand the issues, I am not able to get it running. Any help is very appreciated.