I have a app.js script that I am trying to use to interact with a smart contract. I can read from the contract however, I cannot write to it. The called method countMessages() returns the correct values, however, setMachineInfo() seems to do nothing and produces no error. Both functions work with other scripts.

    var Tx     = require('ethereumjs-tx')
const Web3 = require('web3')
const web3 = new Web3('http://localhost:8043')

const account1 = '' 
const account2 = '' 

const privateKey1 = Buffer.from('', 'hex')
const privateKey2 = Buffer.from('', 'hex')

const contractAddress = '0xc14aC2e543Cc3fB33B53b163311d10F5Dd4337e1'
const abi = []
const contract = new web3.eth.Contract(abi, contractAddress)

var name = web3.utils.toHex("Name")
var message = web3.utils.toHex("Message")
var sendingData = contract.methods.setMachineInfo(account2,name,message).encodeABI()

contract.methods.countMessages().call((err, result) => { console.log("Messages: "+result) })

web3.eth.getTransactionCount(account1, (err, txCount) => {
  // Build the transaction
  const txObject = {
    nonce:    web3.utils.toHex(txCount),
    gasLimit: web3.utils.toHex(33000),
    gasPrice: web3.utils.toHex(web3.utils.toWei('50', 'gwei')),
    to:       contractAddress,
    data: contract.methods.setMachineInfo(account1,name,message).encodeABI()
  console.log("txCount: "+txCount)
  // Sign the transaction
  const tx = new Tx(txObject)

  const serializedTx = tx.serialize()
  const raw = '0x' + serializedTx.toString('hex')

  // Broadcast the transaction
  web3.eth.sendSignedTransaction(raw, (err, txHash) => {
    console.log('txHash:', txHash)
    // Now go check etherscan to see the transaction!

       console.log("Err: "+err)

function countMessages() view public returns(uint){
    return machineAccounts.length;

function getMachineMessage(uint k) view public returns(address, bytes32, bytes32, uint256){

    return(machines[k].delegate,machines[k].name, machines[k].message, machines[k].time);

I get a transaction hash which when I put into mycrypto shows the transaction and the block.

  • The called method countMessages() returns the correct values, however, setMachineInfo() seems to do nothing and produces no error - where exactly are these functions then??? – goodvibration Mar 31 at 20:13
  • Both functions work with other scripts - where exactly are these scripts then, or better yet - what is the difference between these scripts and yours??? – goodvibration Mar 31 at 20:14
  • I'm always amazed to see how much vital information people think they can leave for us to guess, while expecting their problems to be solved. Dumping your code here is simply not enough (let alone, leaving some relevant pieces of it missing)! – goodvibration Mar 31 at 20:16

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.