我使用truffle-contract包来部署使用truffle compile编译的契约
const Web3 = require('web3');
var provider = new Web3.providers.HttpProvider("http://localhost:8545");
const contract = require('truffle-contract');
var FooArtifacts = require("./build/contracts/Foo.json");
var Foo = contract(FooArtifacts);
Foo.setProvider(provider);
var myContractAddress = "0x6139e1b82ffbdbeafbb403a77a04e8374d2521b1";
Foo.new(myContractAddress);运行node deploy.js会出现错误
无法读取未定义的属性“应用”
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'apply' of undefined
at Provider.sendAsync (C:\Users\y\test\node_modules\truffle-contract\contract.js:24:36)
at RequestManager.sendAsync (C:\Users\y\test\node_modules\truffle-contract\node_modules\web3\lib\web3\requestmanager.js:80:19)
at Object.get [as getNetwork] (C:\Users\y\test\node_modules\truffle-contract\node_modules\web3\lib\web3\property.js:116:33)
at C:\Users\y\test\node_modules\truffle-contract\contract.js:512:27
at new Promise (<anonymous>)
at Function.detectNetwork (C:\Users\y\test\node_modules\truffle-contract\contract.js:503:14)
at Function.deployed (C:\Users\y\test\node_modules\truffle-contract\contract.js:451:19)
at Object.<anonymous> (C:\Users\y\test\deploy.js:10:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3使用truffle-contract 3.0.5,web3 1.0.0-beta.34按packages.json。
这里出了什么问题?
https://gist.github.com/nyxynyx/0c48280e5e881b62409047eedc0d2919
pragma solidity ^0.4.18;
import './MyContract.sol';
contract Foo {
uint256 public x;
MyContract myContract;
address myContractAddress;
constructor(address _myContractAddress) public {
myContractAddress = _myContractAddress;
}
function baz() public {
myContract = MyContract(myContractAddress);
x = myContract.baz();
}
}https://ethereum.stackexchange.com/questions/51240
复制相似问题