не удается использовать web3 1.2.1 для вызова функции умного контракта - PullRequest
0 голосов
/ 25 сентября 2019

Я перенес простой умный контракт в свою локальную частную сеть:

pragma solidity >=0.4.22 <0.6.0;
contract test {
    function say() public pure returns (string memory) {
        return "nihao";
    }
}

, а затем написал программу web3 для вызова этого умного контракта.Версия web3 v1.2.1

var express = require("express")
var Web3 = require("web3")
var net = require("net")
var http = require("http")

var web3;
var web3 = new Web3('ws://0.0.0.0:12000');

var abi = ...;
var address = ...;

var t = new web3.eth.Contract(abi, address);
t.methods.say().call().then(console.log);

Произошла ошибка, и я не знаю, как ее исправить.Кажется, ошибка в v1.0.0, и я не знаю, как это происходит сейчас.

(node:30320) UnhandledPromiseRejectionWarning: Error: Returned values aren't val                                                                             id, did it run Out of Gas?
    at ABICoder.decodeParameters (/home/maxuyang/test/node_modules/web3-eth-abi/                                                                             src/index.js:226:15)
    at Contract._decodeMethodReturn (/home/maxuyang/test/node_modules/web3-eth-c                                                                             ontract/src/index.js:465:22)
    at Method.outputFormatter (/home/maxuyang/test/node_modules/web3-eth-contrac                                                                             t/src/index.js:818:46)
    at Method.formatOutput (/home/maxuyang/test/node_modules/web3-core-method/sr                                                                             c/index.js:163:54)
    at sendTxCallback (/home/maxuyang/test/node_modules/web3-core-method/src/ind                                                                             ex.js:473:33)
    at Object.<anonymous> (/home/maxuyang/test/node_modules/web3-core-requestman                                                                             ager/src/index.js:147:9)
    at /home/maxuyang/test/node_modules/web3-providers-ws/src/index.js:127:44
    at Array.forEach (<anonymous>)
    at W3CWebSocket.WebsocketProvider.connection.onmessage (/home/maxuyang/test/                                                                             node_modules/web3-providers-ws/src/index.js:104:36)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/maxuyang/test/node_                                                                             modules/yaeti/lib/EventTarget.js:107:17)
    at W3CWebSocket.onMessage (/home/maxuyang/test/node_modules/websocket/lib/W3                                                                             CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (/home/maxuyang/test/node_modules/websock                                                                             et/lib/W3CWebSocket.js:205:19)
    at WebSocketConnection.emit (events.js:198:13)
    at WebSocketConnection.processFrame (/home/maxuyang/test/node_modules/websoc                                                                             ket/lib/WebSocketConnection.js:554:26)
    at /home/maxuyang/test/node_modules/websocket/lib/WebSocketConnection.js:323                                                                             :40
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:30320) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This                                                                              error originated either by throwing inside of an async function without a catch                                                                              block, or by rejecting a promise which was not handled with .catch(). (rejectio                                                                             n id: 1)
(node:30320) [DEP0018] DeprecationWarning: Unhandled promise rejections are depr                                                                             ecated. In the future, promise rejections that are not handled will terminate th                                                                             e Node.js process with a non-zero exit code.
...