ERC721 mint()返回“无效地址”错误

时间:2018-09-13 05:30:43

标签: node.js express ethereum

我正在尝试使用JavaScript在专用网络中创建ERC721令牌。

我可以通过松露控制台创建ERC721令牌,但通过JavaScript失败。

  

松露(开发)> myToken.mint()

     

{tx:'0xc1dc87a29fbe200ff180df67c01e454818feee433b13331c4ea9268624db​​077b',   收据:{blockHash:   '0xf2ad0c70cda0efca3460ec74866ed61e77647493feb5edf2f81ad2a038c69956',        blockNumber:251489,...

错误消息是

  

“ UnhandledPromiseRejection警告:未处理的承诺拒绝(拒绝ID:2):错误:无效的地址”

我的代码如下:

var Web3 = require('web3');
var BigNumber = require('bignumber.js');
var contract = require("truffle-contract");
var contractJson = require("./build/contracts/MyToken.json");
var MyToken = contract(contractJson);
Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send;
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider(web3Provider));
MyToken.setProvider(web3.currentProvider);

MyToken.deployed().then(function(mytoken) {
    mytoken.mint();
}

minting之前需要其他内容吗?

1 个答案:

答案 0 :(得分:0)

更新代码

这是与您的代码一起使用的更新测试。

import re
s = 'For further details, please contact abc.helpdesk@xyz.com'
new_s = re.sub('[\w\.]+@[\w\.]+', lambda x:f'<a href="{x.group()}">{x.group()}</a>', s)

尝试

设置松露需要一堆样板。试试吧。

'For further details, please contact <a href="abc.helpdesk@xyz.com">abc.helpdesk@xyz.com</a>'

然后将其放入您的package.json

const NFToken = artifacts.require('NFTokenMock');

contract('NFTokenMock', (accounts) => {
    let nftoken;
    const id1 = 1;
    const id2 = 2;
    const id3 = 3;
    const id4 = 40000;

    beforeEach(async () => {
      nftoken = await NFToken.new();
    });

    it('returns correct balanceOf after mint', async () => {
      await nftoken.mint(accounts[0], id1);
      const count = await nftoken.balanceOf(accounts[0]);
      assert.equal(count.toNumber(), 1);
    });
});

并运行mkdir tmp && cd tmp 。另外,我们还需要特殊的技巧才能使用所需的Solidity编译器版本(0.5.1)来获取Truffle:

{
  "dependencies": {
    "@0xcert/ethereum-erc721": "^2.0.0-rc1",
    "truffle": "^5.0.2",
    "web3": "^1.0.0-beta.37"
  }
}

现在设置一个松露项目:

npm install

这是您的合同。将其保存到Contracts / nf-token-mock.sol:

(cd node_modules/truffle && npm install solc@0.5.1)

并将上面的测试文件保存到test / go.js。

如果幸运的话,请运行:mkdir contracts echo > contracts/Migrations.sol <<EOL pragma solidity ^0.5.1; // Boilerplate required, https://github.com/trufflesuite/truffle/issues/1382 contract Migrations {} EOL mkdir Migrations echo > Migrations/1.js <<EOL // Boilerplate required, https://github.com/trufflesuite/truffle/issues/1382 module.exports = ($)=>{}; EOL ,您应该会看到

pragma solidity 0.5.1;

import "@0xcert/ethereum-erc721/src/contracts/tokens/nf-token.sol";
import "@0xcert/ethereum-erc721/src/contracts/ownership/ownable.sol";

/**
 * @dev This is an example contract implementation of NFToken.
 */
contract NFTokenMock is
  NFToken,
  Ownable
{

  /**
   * @dev Mints a new NFT.
   * @param _to The address that will own the minted NFT.
   * @param _tokenId of the NFT to be minted by the msg.sender.
   */
  function mint(
    address _to,
    uint256 _tokenId
  )
    external
    onlyOwner
  {
    super._mint(_to, _tokenId);
  }    
}