Firstly, I have viewed (Uncaught ReferenceError: TruffleContract is not defined) and am getting the same error for my smart contract:

enter image description here

However, I received this error while having the contract script defined in index.html:

<script src="js/truffle-contract.min.js"></script>

Additionally, I have tried adding the turffle contract through npm by adding var contract = require("@truffle/contract"); to app.js and have bundled with browserify which results in an Unexpected identifier in app.js:

enter image description here

Both the solutions purposed in 2018 to this issue seem to have failed. Perhaps I am using browserify with App.js wrong? Or am missing something since the deprecation of truffle-contract to @truffle/contract?

App.js Code:

    App = {
  web3Provider: null,
  contracts: {},
  account: '0x0',
  loading: false,
  tokenPrice: 1000000000000000,
  tokensSold: 0,
  tokensAvailable: 750000,

  init: function() {
    console.log("App initialized...")
    return App.initWeb3();

  initWeb3: function() {
    if (typeof web3 !== 'undefined') {
      // If a web3 instance is already provided by Meta Mask.
      App.web3Provider = web3.currentProvider;
      web3 = new Web3(web3.currentProvider);
    } else {
      // Specify default instance if no web3 instance provided
      App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
      web3 = new Web3(App.web3Provider);
    return App.initContracts();
  initContracts: function() {
    $.getJSON("NyankoCoinSale.json", function(nyankoCoinSale) {
      App.contracts.NyankoCoinSale = TruffleContract(nyankoCoinSale);
      App.contracts.NyankoCoinSale.deployed().then(function(nyankoCoinSale) {
        console.log("Nyanko Coin Sale Address:", nyankoCoinSale.address);
    }).done(function() {
      $.getJSON("NyankoCoin.json", function(nyankoCoin) {
        App.contracts.NyankoCoin = TruffleContract(nyankoCoin);
        App.contracts.NyankoCoin.deployed().then(function(nyankoCoin) {
          console.log("Nyanko Coin Address:", nyankoCoin.address);

        return App.render();

1 Answer 1


Have you tried reading the docs on the @truffle/contract docs?


There are several steps to do before including the truffle-contract.min.js file in the index.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.