一、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;
,remix 工作,但 web3 失败,因为getData
返回的方法的结果不正确(列表模型不增加);