4

I am dealing with a very simple smart contract:

contract MyRegistry {

    struct MyEvent {
        string date; // yyyy/mm/dd
        string desc; // potentially long string
        uint count;  // <= 10000
        bool recorded;
    }

    event Record(bytes32 hash, string desc, uint count);

    function record(bytes32 hash, string date, string desc, uint count) external {
        if (registry[hash].recorded)
            throw;
        registry[hash] = MyEvent(date, desc, count, true);
    }

    mapping (bytes32 => MyEvent) public registry;
}

Now, when trying to call record method from Remix (using MetaMask), everything is ok, contract execution is successful, using the following input:

"10f2e5c1bacf028b41415d0868d5892218df0a4398f0f3ac729e0ac3ac6ed11a", "2016/03/21", "my long description of at least 30 chars", 9876

While, using web3 always fails:

var EthTX = require('ethereumjs-tx')
[...]
var calldata = Registry.record.getData(hash, date, desc, count)
[...]
var transaction = new EthTX({
    to: registry_address,
    gasLimit: 4000000,
    gasPrice: +web3.toWei(10, 'gwei'),
    nonce: myNonce, // previously fetched, problem is not here
    data: calldata,
})

NOTE[0]: I voluntarily omitted the JS code used to sign and send the transaction because the problem is not there. The transaction gets submitted and mined successfully. The problem is during contract execution.

NOTE[1]: I've already tried using bytes instead of string for storing date and desc, but no luck, still the same: works on Remix, does not work with Web3. Also, cannot be lack of gas, otherwise the same tx would fail on Remix too.

Here is the env:

  • Ubuntu 16.04
  • Node 7.6.0
  • web3 0.18.4
  • ethereumjs-tx 1.3.0
  • ethereumjs-util 5.1.1
  • I must generate and sign txs with ethereumjs-tx

Any help is appreciated, thanks.

  • update ethereumjs-tx and web3 – Arslan Smal May 9 '17 at 21:03
  • They are both at the latest version, check it yourself: ethereumjs-tx , ethereumjs-util – user197675 May 9 '17 at 22:26
  • Try adding - pragma solidity ^0.4.0; to the top of the contract. – Malone May 11 '17 at 6:42
  • have you set your web3 provider? Try including both gas and account in your call. I am not familiar with ethereumjs-tx – Karan Kurbur Jan 11 '18 at 1:55
  • you should try with web3 1.0 beta. It has better error reporting and it would allow you to get rid of 3rd party libs as there is a signing function eth.accounts.signTransaction(txObj, pkHex) – Micha Roon Jan 29 '18 at 22:11

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.