Trüffelfehler: Eigenschaft „Aufruf“ von undefiniert [duplizieren] kann nicht gelesen werden

Ich versuche, den folgenden Vertrag in Trüffel auszuführen, der so ziemlich das gleiche HelloWorld ist, aber ich habe den Namen MetaCoin aus dem Trüffelbeispiel beibehalten. Ich habe diesen , diesen und diesen Beitrag gelesen, der sich auf dieses Problem bezieht. Diese Korrekturen funktionieren in meinem Fall nicht.

Ich verwende Truffle v3.2.1 und den testrpc-Client

    contract MetaCoin {
        uint public balance;

        function MetaCoin(){
            balance = 1000;
        }
    }

Ich kompiliere, migriere und führe die Konsole aus und überprüfe, ob sie bereitgestellt wurde:

    truffle(development)> MetaCoin.deployed();

Und die Ausgabe scheint so weit richtig zu sein ...

    TruffleContract {
    constructor:
       { [Function: TruffleContract]
 _static_methods:
  { setProvider: [Function: setProvider],
    new: [Function: new],
    at: [Function: at],
    deployed: [Function: deployed],
    defaults: [Function: defaults],
    hasNetwork: [Function: hasNetwork],
    isDeployed: [Function: isDeployed],
    detectNetwork: [Function: detectNetwork],
    setNetwork: [Function: setNetwork],
    resetAddress: [Function: resetAddress],
    link: [Function: link],
    clone: [Function: clone],
    addProp: [Function: addProp],
    toJSON: [Function: toJSON] },
 _properties:
  { contract_name: [Object],
    abi: [Object],
    network: [Function: network],
    networks: [Function: networks],
    address: [Object],
    links: [Function: links],
    events: [Function: events],
    binary: [Function: binary],
    unlinked_binary: [Object],
    schema_version: [Function: schema_version],
    updated_at: [Function: updated_at] },
 _property_values: {},
 _json:
  { contract_name: 'MetaCoin',
    default_network: undefined,
    abi: [Object],
    unlinked_binary: '0x6060604052346000575b6103e86000555b5b60708061001f6000396000f300606060405263ffffffff60e060020a600035041663b69ef8a881146022575b6000565b34600057602c603e565b60408051918252519081900360200190f35b600054815600a165627a7a7230582041830854cedee45f2bd4eeaf84234adc0711a5415d238ee5c39b677b533974c30029',
    networks: [Object],
    schema_version: '0.0.5',
    updated_at: 1491813299298 },
 setProvider: [Function: bound setProvider],
 new: [Function: bound new],
 at: [Function: bound at],
 deployed: [Function: bound deployed],
 defaults: [Function: bound defaults],
 hasNetwork: [Function: bound hasNetwork],
 isDeployed: [Function: bound isDeployed],
 detectNetwork: [Function: bound detectNetwork],
 setNetwork: [Function: bound setNetwork],
 resetAddress: [Function: bound resetAddress],
 link: [Function: bound link],
 clone: [Function: bound clone],
 addProp: [Function: bound addProp],
 toJSON: [Function: bound toJSON],
 web3:
  Web3 {
    _requestManager: [Object],
    currentProvider: [Object],
    eth: [Object],
    db: [Object],
    shh: [Object],
    net: [Object],
    personal: [Object],
    bzz: [Object],
    settings: [Object],
    version: [Object],
    providers: [Object],
    _extend: [Object] },
 class_defaults:
  { from: '0x3134fbda1c6ff76deb6c336b8460794ec842d2ae',
    gas: 4712388,
    gasPrice: 100000000000 },
 currentProvider: HttpProvider { host: 'http://localhost:8545', timeout: 0 },
 network_id: '1491808773134' },
      abi:
       [ { constant: true,
   inputs: [],
   name: 'balance',
   outputs: [Object],
   payable: false,
   type: 'function' },
 { inputs: [], payable: false, type: 'constructor' } ],
      contract:
      Contract {
 _eth:
  Eth {
    _requestManager: [Object],
    getBalance: [Object],
    getStorageAt: [Object],
    getCode: [Object],
    getBlock: [Object],
    getUncle: [Object],
    getCompilers: [Object],
    getBlockTransactionCount: [Object],
    getBlockUncleCount: [Object],
    getTransaction: [Object],
    getTransactionFromBlock: [Object],
    getTransactionReceipt: [Object],
    getTransactionCount: [Object],
    call: [Object],
    estimateGas: [Object],
    sendRawTransaction: [Object],
    signTransaction: [Object],
    sendTransaction: [Object],
    sign: [Object],
    compile: [Object],
    submitWork: [Object],
    getWork: [Object],
    coinbase: [Getter],
    getCoinbase: [Object],
    mining: [Getter],
    getMining: [Object],
    hashrate: [Getter],
    getHashrate: [Object],
    syncing: [Getter],
    getSyncing: [Object],
    gasPrice: [Getter],
    getGasPrice: [Object],
    accounts: [Getter],
    getAccounts: [Object],
    blockNumber: [Getter],
    getBlockNumber: [Object],
    protocolVersion: [Getter],
    getProtocolVersion: [Object],
    iban: [Object],
    sendIBANTransaction: [Function: bound transfer] },
 transactionHash: null,
 address: '0xdfefe34eb214332f4188c5582ddba2c1ea5cd623',
 abi: [ [Object], [Object] ],
 balance:
  { [Function: bound ]
    request: [Function: bound ],
    call: [Function: bound ],
    sendTransaction: [Function: bound ],
    estimateGas: [Function: bound ],
    getData: [Function: bound ],
    '': [Circular] },
 allEvents: [Function: bound ] },
      balance:
     { [Function]
 call: [Function],
 sendTransaction: [Function],
 request: [Function: bound ],
 estimateGas: [Function] },
      sendTransaction: [Function],
      send: [Function],
      allEvents: [Function: bound ],
     address: '0xdfefe34eb214332f4188c5582ddba2c1ea5cd623',
     transactionHash: null }

Und jetzt versuche ich, das Gleichgewicht auf verschiedene Arten zu überprüfen:

    truffle(development)> meta = MetaCoin.deployed()
    ...
    truffle(development)> meta.balance.call()
    OR
    truffle(development)> MetaCoin.deployed().balance.call()
    OR
    truffle(development)> meta.balance.call().then(console.log)

und das ist der Fehler, den ich bekomme!

    TypeError: Cannot read property 'call' of undefined
        at evalmachine.<anonymous>:1:28
        at ContextifyScript.Script.runInContext (vm.js:32:29)
        at Object.runInContext (vm.js:87:6)
        at TruffleInterpreter.interpret (C:\Users\310267627\AppData\Roaming \npm\node_modules\truffle\lib\repl.js:136:17)
        at bound (domain.js:280:14)
        at REPLServer.runBound [as eval] (domain.js:293:12)
        at REPLServer.onLine (repl.js:536:10)
        at emitOne (events.js:96:13)
        at REPLServer.emit (events.js:191:7)
        at REPLServer.Interface._onLine (readline.js:241:10)

Irgendwelche Ideen?!

siehe ethereum.stackexchange.com/questions/11935/…

Antworten (1)

Trüffel 3.x?

Versuchen Sie, auf zurückgegebene Versprechen zu warten ...

truffle(development)> var meta;
truffle(development)> var balance;
truffle(development)> MetaCoin.deployed().then(function(instance) { meta = instance; });
truffle(development)> meta.balance().then(function(bal) { balance = bal; });

truffle(development)> balance;
[big num ... ]
truffle(development)> balance.toString(10);
human readable ...