I am new to Ethereum. I have created private blockchain using Geth on my local and trying to deploy my smart contract using java web3j SDK. I am able to deploy my contract using java and getting contract address but when I try to call createItem() method to set some values then its not able to set those values. Infact, if I will try to access the contract using the contract address in remix, I am still not able to set those value. Whilst if I will deploy my contract from remix IDE then I am able to call createItem() methods from both remix and my java code. Here is my contract file Item.sol
pragma solidity >=0.4.22 <0.6.2;
contract Item{
uint id;
uint items;
uint startDate;
uint endDate;
bool isValid;
address public owner;
constructor() public {
owner = msg.sender;
isValid = false;
}
modifier restricted() {
require(
msg.sender == owner,
"Only owner can call this."
);
_;
}
function createItem(uint _id, uint _startDate, uint _endDate, uint _items, bool _isValid) public {
id = _id;
startDate = _startDate;
endDate = _endDate;
items = _items;
isValid = _isValid;
}
function validateItem() public {
isValid = true;
}
function getItemData() public view returns (uint, uint, uint, uint, bool) {
return (id, startDate, endDate, items, isValid);
}
function getId() public view returns (uint) {
return id;
}
function getItems() public view returns (uint) {
return items;
}
function getStartDate() public view returns (uint) {
return startDate;
}
function getEndDate() public view returns (uint) {
return endDate;
}
function isValidItem() public view returns (bool) {
return isValid;
}
}
This my java code to deploy the contract
Web3j web3j = Web3j.build(new HttpService());
Credentials credentials = WalletUtils.loadCredentials(“password”, PRIVATE_KEY);
String contractAddress = Item.deploy(web3j, credentials, new DefaultGasProvider()).send().getContractAddress();
log.info("contract deployed at address : " + contractAddress);
Item contract = loadContract(contractAddress, web3j, credentials);
TransactionReceipt receipt = contract.createItem(BigInteger.valueOf(20), BigInteger.valueOf(1577880090),
BigInteger.valueOf(1580472090), BigInteger.valueOf(1000), true).send();