首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用松露部署错误-契约:无法读取未定义的属性“应用”

使用松露部署错误-契约:无法读取未定义的属性“应用”
EN

Ethereum用户
提问于 2018-06-14 15:51:17
回答 1查看 1.3K关注 0票数 1

我使用truffle-contract包来部署使用truffle compile编译的契约

deploy.js

代码语言:javascript
复制
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会出现错误

无法读取未定义的属性“应用”

代码语言:javascript
复制
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。

这里出了什么问题?

Foo.json伪影

https://gist.github.com/nyxynyx/0c48280e5e881b62409047eedc0d2919

Foo.sol

代码语言:javascript
复制
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();
    }
}
EN

回答 1

Ethereum用户

回答已采纳

发布于 2018-06-14 17:43:42

这是web3 1.0版。

解决办法:

代码语言:javascript
复制
if (typeof contract.currentProvider.sendAsync !== "function") {
  contract.currentProvider.sendAsync = function() {
    return contract.currentProvider.send.apply(
      contract.currentProvider,
          arguments
    );
  };
}

信贷1credit2

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/51240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档