首先,web3版本:1.0.0-beta.36
合同代码为:
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;
}
}
我通过remix和web3.js发送交易:
myContract.methods.createData(
key,
addressA
).send({
from: addressB
})
问题是:
modelOwner[newModelId] = _owner;
中的代码createData
时,web3和remix都可以工作(列表模型增加); modelOwner[newModelId] = _owner;
时,重新混合工作,但是web3失败,因为返回的方法getData
的结果不正确(列表模型没有增加);