关于部署合约时报错提示ReferenceError: TruffleContract is not defined

TruffleContract(data)实例合约是不是用不了 初始化web3是正常的但是用TruffleContract(data)初始化实例的时候就报错提示 image.png

代码如下

App={
   web3Provider:null,
   contracts:{},

    init:function(){
       return App.initWeb3();
    },
//初始化web3
initWeb3:function(){
    if(ethereum){
        //ethereum存在就是新版本
        App.web3Provider=ethereum;
        //web3Provider = ethereum;
    try {
         ethereum.request({ method: 'eth_requestAccounts' });

        }
    catch (error) {alert("用户取消授权");  }}

    else if(web3){
        //判断是否是旧版本metamask
        //web3=new Web3(web3.currentProvider);
        web3Provider = web3.currentProvider;

    }else{
        //未安装metamask
        web3Provider = new Web3.providers.HttpProvider('http://localhost:9545');
         }
    web3 = new Web3(App.web3Provider);
    console.log(web3);
    App.initConstract();

},

//初始化合约
initConstract:function(){
    //通过getJSON拿到合约文件
 $.getJSON('../build/contracts/lnfoContract.json',function(data){
     //就可以拿到合约对象TruffleContract(data)
    console.log(TruffleContract(data));
    // App.contracts.lnfoContract.setProvider(App.web3Provider);
    // return App.getInfo();
    //console.log(App.contracts.lnfoContract);
 })

},

},

window.addEventListener("load", function() {
    App.init();
})
请先 登录 后评论

2 个回答

王long
请先 登录 后评论
王long
请先 登录 后评论
  • 1 关注
  • 0 收藏,1863 浏览
  • 王long 提出于 2022-01-18 22:40

相似问题