0

when i call any functionality of smart contract it returns me what its suppose to but doesnt reflect anyy changes when i query it. Its like the transaction never took place itself although it gave the right result from smart contract.Im using test-rpc. Have tested contract in truffle. and solidity browser. This is the simplified version of code that I've made.

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

console.log("Talking with a geth server", web3.version.api);

function test(){

var sourceCode = fs.readFileSync('contracts/digitalToken.sol','utf8')

var compiled = solc.compile(sourceCode);

console.log(compiled.contracts[":digitalToken"]);

var abiArray = compiled.contracts[":digitalToken"].interface;

abiArray = JSON.parse(abiArray);

var MyContract = web3.eth.contract(abiArray);

var address = "0x1f81b5fa31d049b70556628cc01f22d362c41084";

var contractInstance = MyContract.at(address);

console.log(contractInstance);

var value=executeAddvid(contractInstance)

  console.log({message: "Success",value:value});

  console.log('after passing--');

  console.log({message: "Success",value:value});
var value1=readVidByUser(contractInstance);

console.log({message: "Success",value:value1});

  console.log('after passing--');

  console.log({message: "Success",value:value1});
}

function executeAddvid(contractInstance){

record = contractInstance;

return record.addVid.call('0x0000000000000000000000000000000000000124',5,"ronaldo","0xc9f5a0572d95d5dea1331edcc192dacef51ecbb7",1000000000000000000);

}

function readVidByUser(contractInstance){

record = contractInstance;

return record.readVidByUser.call('0x0000000000000000000000000000000000000124','0x1f81b5fa31d049b70556628cc01f22d362c41084');

}

test();
1

When you use .call, as in record.addVid.call(...), you are not sending a transaction, but executing the call locally. For state-changing functions you want to use .transact, as in

record.addVid.call('0x0000000000000000000000000000000000000124',5,"ronaldo","0xc9f5a0572d95d5dea1331edcc192dacef51ecbb7",1000000000000000000, {from:eth.coinbase})
  • The problem was the call function only, didnt realise it should be used for constant functions only. Thanks. – Shubhabrata Mukherjee Jul 4 '17 at 5:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.