How to solve "cannot read property 'anonymous' of undefined" error message

I am currently making an erc20 based token factory using openzepplin. I do not understand why these problems are happening at the moment, and I would like to see how i can solve this problem.

it is my smart contract source code

pragma solidity ^0.5.0;

import "./Factory.sol";
import "./TokenizeFT.sol";

// @title FT Factory - Allows creation of custom token.
// @author hyungchul.park

contract FTFactory is Factory {
    function create(string memory _name, string memory _symbol, uint8 decimals) public returns (TokenizeFT tokenAddress){
        tokenAddress = new TokenizeFT(_name, _symbol, decimals);
        register(tokenAddress);
    }
}

it is my TokenizeFT.sol contract

pragma solidity ^0.5.0;

import "../../node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "../../node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";

contract TokenizeFT is ERC20, ERC20Detailed {
    constructor(string memory _name, string memory _symbol, uint8 decimals) public ERC20Detailed(_name, _symbol, decimals){
        _mint(msg.sender, 10000 * (10 ** uint256(decimals)));
    }
}

it is my Factory.sol

pragma solidity ^0.5.0;

import "./TokenizeFT.sol";

contract Factory {
    // events
    event ContractInstantiation(address sender, TokenizeFT instantiation);

    // storage
    mapping(address => bool) public isInstantiation;
    TokenizeFT[] public ftlist;
    mapping(address => TokenizeFT[]) public instantiations;

    // public function
    function getInstantiationCount(address creator) public view returns (uint) {
        return instantiations[creator].length;
    }

    // internal function
    function register(TokenizeFT instantiation) internal {
        ftlist.push(instantiation);
        instantiations[msg.sender].push(instantiation);
        emit ContractInstantiation(msg.sender, instantiation);
    }
}

below is error screen pic

Hello @clay! Can you post your Javascript as well? I think it may be the source of the problem here.

Is this what you want?

1 Like

const Web3 = require(‘web3’);
path = require(‘path’);
tokenizeABI = require(path.join(__dirname + ‘/…/…/truffle/build/contracts/TokenizeNFT.json’));
ftABI = require(path.join(__dirname + ‘/…/…/truffle/build/contracts/FTFactory.json’));

const web3 = new Web3( new Web3.providers.HttpProvider(“http://127.0.0.1:8545”));
const contractAddress = “0x61A3c0729D9C6ABd283FA49Ef482fF626750a2A3”;
const FTFactoryAddress = “0xbd2E33D98352621546e14AC599ae4454172013F2”;

let TokenizeContract = new web3.eth.Contract(tokenizeABI.abi, contractAddress);
let FTFactoryContract = new web3.eth.Contract(ftABI.abi, FTFactoryAddress);

const create_ft = (req, res) => {
const tokenId = req.params.tokenId;
let tokenName = req.body.tokenName;
let symbol = req.body.symbol;
let decimals = req.body.decimals;
let owner = req.body.owner;

console.log(tokenName);
console.log(symbol);
console.log(decimals);
console.log(owner);
FTFactoryContract.methods.create(tokenName, symbol, decimals).send({from: owner, gas: 2000000}).then((receipt) => {
console.log(receipt);
res.status(201).json({‘resMessage’: ‘ERC20 Token Create Success’});
});
}

additional web3.js code

@clay I am not sure if that is the cause of your problem but you have a typo here "...TokenizeNFT.json" instead of "...TokenizeFT.json"

3 Likes