개인 트렌젝션 조회

 

index.js 


const TronWeb = require('tronweb');
const fullNode = 'https://api.trongrid.io';
const solidityNode = 'https://api.trongrid.io';
const eventServer = 'https://api.trongrid.io';
const privateKey = '123';
const app = async () => {
 try {
  const tronWeb = new TronWeb(
      fullNode,
      solidityNode,
      eventServer,
      privateKey
  );
  tronWeb.setDefaultBlock('latest');
  const nodes = await tronWeb.isConnected();
  const connected = !Object.entries(nodes).map(([name, connected]) => {
   if (!connected)
           console.error(`Error: $ {
    name
   }
   is not connected`);
   return connected;
  }
  ).includes(false);
  const gTransactions = await tronWeb.trx.getTransactionsFromAddress("THEwbtZuspuBBVzJdhHo3c7C7gL3xC3XqW", 30, 0);
  const gTRelated = await tronWeb.trx.getTransactionsRelated("THEwbtZuspuBBVzJdhHo3c7C7gL3xC3XqW", "all", 30, 0);
  const gBalance = await tronWeb.trx.getBalance("THEwbtZuspuBBVzJdhHo3c7C7gL3xC3XqW");
  const gBandwidth = await tronWeb.trx.getBandwidth("THEwbtZuspuBBVzJdhHo3c7C7gL3xC3XqW");
  console.log("getTransactionsFromAddress : ", gTransactions);
  console.log("getTransactionsRelated : ", gTRelated);
  console.log("getBalance : ", gBalance);
  console.log("getBandwidth : ", gBandwidth);
 }
 catch (error) {
  console.log('Task Failure',error);
 }
};
app();

getTransactionsFromAddress : 해당주소가 from으로 들어간곳 출력

getTransactionsToAddress : 해당주소가 to로 들어간곳 출력

getTransactionsRelated : 해당주소를 포함하는 전체 출력

 

잔액과 대역폭까지 했다.

 

잔액은 소수점 6자리다.

31,100,001      31 tron 있는거다.

Bandwidth는 첫 계좌 개통시 0.1 tron 나가고 그뒤로 Bandwidth대역폭을 쓴다.

다 쓰면 또 차감되고 시간지나면 차고 그렇다.

트렌젝션 무한루프를 막고 무료 쿠폰이 충전된다 생각하면 된다.

 

 

실행 결과

   { ret: [ [Object] ],
    signature:
     [ '235227d616000810d912ba476e6a5e47634e2c9f137517651c3373ae2543b2

df09

66fb435d374bca80a086661a3a426976cb13792ab27e62b619b43a7dd3429101' ],
    txID: 'bb9d030ade9c3582ae087ca9c9a7a28b9472291303f7f6898a235f1acb362b64',
    contract_address: '41f71d6c850fd7ad1dc5183b2d4ecb3fefc990d5ed',
    raw_data:
     { contract: [Array],
       ref_block_bytes: 'b60f',
       ref_block_hash: '3eaf55dc91a030aa',
       expiration: 1545012204000,
       fee_limit: 100000000,
       timestamp: 1545012147303 },
    direction: 'from' } ]
getBalance :  29654158819
getBandwidth :  3967
root@tkpark-VirtualBox:~/tron-web/examples/server# clear
root@tkpark-VirtualBox:~/tron-web/examples/server# nodejs index.js
getTransactionsFromAddress :  []
getTransactionsRelated :  [ { ret: [ [Object] ],
    signature:
     [ '568bba26156139fcd20b3128a5748ae32dba482a308d5f1afdcfbf621

316c888

ea529b07a30b90961de27393c9e046e6ef54abed7966db0754af611a824108e800' ],
    txID: '59c8d68a939b87180da5ddf78c2f03257e0a6ed682711ae5f7758835

7c138e34',
    raw_data:
     { contract: [Array],
       ref_block_bytes: '423f',
       ref_block_hash: 'd68872a44e72ff02',
       expiration: 1545119898000,
       timestamp: 1545119838729 },
    direction: 'to' },
  { ret: [ [Object] ],
    signature:
     [ 'ac0cd98aee3d6714686f92784a92e4dbc3f0fd9b888ea35c37c63ce

5795202e655be54b64412295fb14bf644ec39b1f2a34e35d93fc782811c5ccaff4

28a527c01' ],
    txID: '1658f71e62004a843f1c5817436573ba22210e44ff885fd5d18b3fae

ca386268',
    raw_data:
     { contract: [Array],
       ref_block_bytes: '4236',
       ref_block_hash: 'f5fe36a0efa6e5fe',
       expiration: 1545119871000,
       timestamp: 1545119813541 },
    direction: 'to' },
  { ret: [ [Object] ],
    signature:
     [ 'fd2d0b3804f92287e93c512aef3c65e6cd546821da7750ac8ca9bd79f1

a2bdc3a3052b

d216d92d34dfa376becd2b2f6b29b3bb4fd998742c5ac0c3a4e45972fa00' ],
    txID: '63a05187e65543353cbd2a8d5f8bb704e9a8526f4dabd6c95802ef825a0

c3d92',
    raw_data:
     { contract: [Array],
       ref_block_bytes: '422a',
       ref_block_hash: '94aa6a7ebb38340d',
       expiration: 1545119835000,
       timestamp: 1545119778452 },
    direction: 'to' },
  { ret: [ [Object] ],
    signature:
     [ 'af1d8a405433ea655667ead45252e0c0eb9262d4657ad600cea0a7a

5f4c2797

9cf4e5c6c0834a318392f77a02be5ed0de16bc13d04ba4f693c23bfd04da77e3100' ],
    txID: '58298adfe44ab3342d36bd49fa215e2445ac022c14cc76b39442ee

eb8e1206c7',
    raw_data:
     { contract: [Array],
       ref_block_bytes: '420c',
       ref_block_hash: '3cb12e5531462d93',
       expiration: 1545119745000,
       timestamp: 1545119687069 },
    direction: 'to' } ]
getBalance :  31100001
getBandwidth :  5000

 

 

root@tkpark-VirtualBox:~/project/myapp/routes# nodejs ex3.js
getTransactionsFromAddress :  []
getTransactionsRelated :  []
getBalance :  4596610
getBandwidth :  43
root@tkpark-VirtualBox:~/project/myapp/routes#

 

 

 

 

 

블로그 이미지

iesay

,