truffle各类报错解决:Error encountered, bailing;Error: VM Exception while processing transaction: revert;TypeError: Cannot read property ‘apply’ of undefined;UnhandledPromiseRejectionWarning;DeprecationWarning;UnhandledPromiseRejectionWarning;out of gas
更多区块链技术与应用分类:
1.truffle migrate时报错
错误描述
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: VM Exception while processing transaction: revert
解决方法
“revert”一般是require语句导致,部署合约时,运行constructor函数,故可能是构造函数中有bug :
constructor (){
// 其中有bug;
}
通过逐步注释,得出,注释掉该句
constructor () public payable {
require(HOUSE_POOL_WIN_PRIZE_PERCENT + HOUSE_POOL_BONUS_PERCENT + HOUSE_POOL_NEXT_ROUND_PERCENT + HOUSE_POOl_ADMIN_PERCENT == 1 ether);
house = msg.sender;
playState = PlayState.Created;
OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475);
--> oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS); // 该句出错
lottery3DNumber = Lottery3DNumber(msg.sender);
}
2.truffle-contract 1.0.0报错
错误描述
TypeError: Cannot read property 'apply' of undefined
解决方法
每个deployed合约执行:
if (typeof func.currentProvider.sendAsync !== "function") {
func.currentProvider.sendAsync = function () {
return func.currentProvider.send.apply(
func.currentProvider, arguments
);
};
}
3.调用合约方法时报错:
错误描述
(node:8724) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: First argument must be a string or Buffer
(node:8724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
解决方法
res.end(issue) //issue为promise不能直接使用 改为: res.end(JSON.stringify(issue))
4. 调用合约中mapping结构数据时出错
错误描述
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Invalid number of arguments to Solidity function
解决方法
必须给参数:
return lotteryGameEngineInst.allBet(0); // 给参数
5.部署合约时报错
错误描述
out of gas
解决方法
在truffle里添加gas费
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*",
gas: 8000000,
}
},
原文链接:truffle相关ERROR解决记录