I have ReactJS working to read data from my blockchain but I cannot update the blockchain. Here is my code to read the blockchain which works -
var reviewContract = ETHEREUM_CLIENT.eth.contract(reviewContractABI).at(reviewContractAddress)
var reviewData = reviewContract.getReviews()
When I try and update it fails:
reviewContract.addReview("company1", "trevor lee oakley", 1)
Uncaught Error: invalid address
at inputAddressFormatter (http://localhost:3000/static/js/bundle.js:45751:12)
at inputTransactionFormatter (http://localhost:3000/static/js/bundle.js:45577:21)
at http://localhost:3000/static/js/bundle.js:45881:29
at Array.map (native)
at Method.formatInput (http://localhost:3000/static/js/bundle.js:45880:33)
at Method.toPayload (http://localhost:3000/static/js/bundle.js:45906:24)
at Eth.send [as sendTransaction] (http://localhost:3000/static/js/bundle.js:45931:31)
at SolidityFunction.sendTransaction (http://localhost:3000/static/js/bundle.js:48458:27)
at SolidityFunction.execute (http://localhost:3000/static/js/bundle.js:48544:38)
at App.componentWillMount (http://localhost:3000/static/js/bundle.js:32663:23)
I have this code to add.
pragma solidity ^0.4.8;
contract Review {
Review[] public reviews;
struct Review {
bytes32 companyName;
bytes32 companyReviewer;
uint companyReview;
}
function addReview (bytes32 _companyName, bytes32 _companyReviewer, uint _companyReview) returns (bool success) {
Review memory newReview;
newReview.companyName = _companyName;
newReview.companyReviewer = _companyReviewer;
newReview.companyReview = _companyReview;
reviews.push(newReview);
return true;
}
function getReviews() constant returns (bytes32[], bytes32[], uint[]) {
uint length = reviews.length;
bytes32[] memory companyNames = new bytes32[](length);
bytes32[] memory companyReviewers = new bytes32[](length);
uint[] memory companyReviews = new uint[](length);
for (uint i=0; i<reviews.length; i++) {
Review memory currentReview;
currentReview = reviews[i];
companyNames[i]=currentReview.companyName;
companyReviewers[i]=currentReview.companyReviewer;
companyReviews[i]=currentReview.companyReview;
}
return (companyNames, companyReviewers, companyReviews);
}
}
The contract works in truffle so I know -
- The solidity is OK
- Access to the blockchain is OK
- Update fails.
Any help is welcome.
web3.eth.defaultAccount = web3.eth.coinbaseon your client console as you are trying to call a function which performs state write operation. Let me know the result – Aniket Apr 17 '17 at 14:55web3.eth.defaultAccount = web3.eth.coinbase
– Trevor Lee Oakley Apr 17 '17 at 17:11