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() {
            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();
  • maybe you should wait until the transaction which include your contract is mined :/ – Majd TL Jan 31 at 15:00
  • The problem was my abi ...I tried to create abi using tuffle and it had some problem. When I tried with the abi created by remix ide ...It worked!! – Ruchita Feb 10 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.