Py学习  »  docker

Tron智能合约Web API不适用于Docker快速启动网络

Daniel Specht • 4 年前 • 312 次点击  

我跟随 Quickstart with TRON Docker 从官方的tron delopers页面设置本地测试网。

  • 启动tron docker快速启动成功
  • 与tron studio的智能合约部署成功
  • 使用与tron studio的合同是成功的

使用教程中的代码,我可以获得合同,但当我使用合同的函数时,承诺就失效了。

dockerstate.js文件:

const TronWeb = require('tronweb');
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider('http://127.0.0.1:8090');    //Your local TVM URL  
const solidityNode = new HttpProvider('http://127.0.0.1:8091');
const eventServer = 'http://127.0.0.1:8092';
const privateKey = 'da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0';

const tronWeb = new TronWeb(
    fullNode,
    solidityNode,
    eventServer,
    privateKey
);

async function changestate(){

  let contractAddress = 'TAA6PHMkrQs5bZp7cBYcfdWES9EMb5BZaK';   //Your address
  let contract = await tronWeb.contract().at(contractAddress);
  let resultPost = await contract.postMessage("TRON to the Future").send();
  let resultGet = await contract.getMessage().call();
  console.log('resultGet: ', resultGet);
}

changestate()

控制台输出:

$ node dockerstate.js
(node:9616) UnhandledPromiseRejectionWarning: Error: timeout of 30000ms exceeded
at createError (C:\Users\Daniel Specht\Documents\repos\docker-tron-quickstart\app\node_modules\axios\lib\core\createError.js:16:15)
at Timeout.handleRequestTimeout [as _onTimeout] (C:\Users\Daniel Specht\Documents\repos\docker-tron-quickstart\app\node_modules\axios\lib\adapters\http.js:216:16)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)
(node:9616) 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(). (rejection id: 2)
(node:9616) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a
non-zero exit code.

Docker控制台输出:

FULL-NODE /wallet/getcontract
[Output {"bytecode":"608060405234801561001057600080fd5b5061036b806100206000396000f30060806040526004361061004b5763ffffffff7c010000000000000000000000000000000000000000000000000000
...  46ac33f208574882cc1a01b78855381ea6bf9978caab7bee73880029","consume_user_resource_percent":100,"name":"HelloWorld","origin_address":"410e93d739dbb8874f599a8bc29c7faefbf8eeab0f","a
bi":{"entrys":[{"outputs":[{"type":"string"}],"inputs":[{"name":"value","type":"string"}],"name":"postMessage","stateMutability":"Nonpayable","type":"Function"},{"outputs":[{"type":"string"}],"constant":true,"name":"getMessage","stateMutability":"View","type":"Function"},{"inputs":[{"name":"res","type":"uint256"}],"name":"test","type":"Event"}]},"contract_address":"41a6e9867de6f1674a2cadbfbbedd60e0ad63700c8"}
GET 200 2362 - 3.690 ms
POST   -  ms

似乎使用web api智能合约不起作用。 有什么建议,问题在哪里,如何解决或调试?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40271
 
312 次点击