5

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

 2 years ago
source link: https://learnblockchain.cn/question/3014
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

关于部署合约时报错提示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();
})

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK