Ich verwende das truffle-contract
Paket, um einen Vertrag bereitzustellen, der mit kompiliert wurdetruffle compile
deploy.js
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);
Laufen node deploy.js
gibt den Fehler
Eigenschaft 'apply' von undefined kann nicht gelesen werden
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
Unter Verwendung von truffle-contract
3.0.5 web3 1.0.0-beta.34
gemäß packages.json.
Was ist hier schief gelaufen?
Foo.json-Artefakt
https://gist.github.com/nyxynyx/0c48280e5e881b62409047eedc0d2919
Foo.sol
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();
}
}