【问题标题】:Creating a struct causes weird behaviors in remix ide创建结构会导致 remix ide 出现奇怪的行为
【发布时间】:2018-08-05 02:51:24
【问题描述】:

问题: Remix 产生奇怪的行为,字符串参数后跟数组参数

转载:

contract ItemMarket is ERC721 {
  struct Item {
    string name;
    uint[3] others;
  }

  Item[] public items;

  function createItem(string _name, uint[6] _others) public {
    uint tokenId = items.push(Item({name: _name, traits:_traits})) - 1;
  }
}

当您调用带有参数"hello", [1,2,3] 的remix 中的createItem() 时,第一个参数将转换为\u0000。通过 MEW 与合约交互时,具有相同参数的相同函数调用可以正常工作

【问题讨论】:

标签: ethereum solidity remix


【解决方案1】:

现在可以在最新版本的 Remix IDE 中使用:

pragma solidity 0.5.1;

import "https://github.com/0xcert/ethereum-erc721/src/contracts/tokens/nf-token.sol";

contract ItemMarket is ERC721 {
  struct Item {
    string name;
    uint[3] traits;
  }

  Item[] public items;

  function createItem(string memory name, uint[3] memory traits) public {
    items.push(Item({name:name, traits:traits})) - 1;
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    相关资源
    最近更新 更多