first, web3 version: 1.0.0-beta.36

the contract code is:

pragma solidity ^0.4.25;

contract Main {
  struct Model {
    uint256 key;
    uint64 createTime;

  Model[] public models;

  mapping(uint256 => address) public modelOwner;

  function total() view public returns (uint256) {
    return models.length;

  function getData(uint256 _tokenId) view returns ( uint256, uint64){

    Model _model = models[_tokenId];
    return  (_model.key, _model.createTime);

  function createData(uint256 _key, address _owner) returns (uint){

    Model memory _model = Model({key : _key, createTime : uint64(now)});

    uint256 newModelId = models.push(_model) - 1;

    // modelOwner[newModelId] = _owner;

    return newModelId;

I send transaction by remix and web3.js:

 from: addressB 

the problem is :

  1. when I remove the code modelOwner[newModelId] = _owner; in function createData, web3 and remix both work (List models increase);
  2. when I add modelOwner[newModelId] = _owner;, remix work, but web3 failed, because the result of the method getData returned is not correct (List models not increase);
  • One difference between remix and web3.js is that web3 uses a default gas of 90k and remix will estimate the required gas. You can add gas parameter to send, like .send({ from: "0x....", gas: 1000000 }). – Ismael Nov 5 '18 at 6:18
  • @Ismael yes, I forgot the difference, and web3js works after I add the gas – JoShin Nov 5 '18 at 10:30

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.