개인 트렌젝션 조회

 

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

,

출처 : https://developers.tron.network/v3.0/reference#sign

참고 : https://github.com/tronprotocol/tron-web/issues/104

 

 

index.js

const TronWeb = require('../../dist/TronWeb.node.js');

const fullNode = 'https://api.shasta.trongrid.io';
const solidityNode = 'https://api.shasta.trongrid.io';
const eventServer = 'https://api.shasta.trongrid.io';
const privateKey = '개인키';

const app = async () => {
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);

    if (!connected)
        return;
    const sendTransaction = await tronWeb.transactionBuilder.sendTrx('TMDBC4DoS1yQCjBgnPBJWnfTZN9rAKBUHc', 1, 'TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih');

    console.group('Unsigned send TRX transaction');
    console.log('- Recipient: TGEJj8eus46QMHPgWQe1FJ2ymBXRm96fn1');
    console.log('- Transaction:\n' + JSON.stringify(sendTransaction, null, 2), '\n');
    console.groupEnd();

};
app(); 

 

트랜젝션 생성은 되는거 같은데

TronLink에서 보면 송금은 안되있다.

 

root@tkpark-VirtualBox:~/tron-web/examples/server# nodejs index.js
Unsigned send TRX transaction
  - Recipient: TGEJj8eus46QMHPgWQe1FJ2ymBXRm96fn1
  - Transaction:
  {
    "txID": "1af7a6cdb907dbd8477f65ecb51bb4c64e874fa5d4ca1639b65985b0125148bc",
    "raw_data": {
      "contract": [
        {
          "parameter": {
            "value": {
              "amount": 1,
              "owner_address": "41b0720a94d13ef83434e1385b543c9291c79a6d14",
              "to_address": "417b4db2232332c2267271d10c55c126fae6f67de1"
            },
            "type_url": "type.googleapis.com/protocol.TransferContract"
          },
          "type": "TransferContract"
        }
      ],
      "ref_block_bytes": "2658",
      "ref_block_hash": "3183fbce05f7e625",
      "expiration": 1545098463000,
      "timestamp": 1545098404591
    }
  }

root@tkpark-VirtualBox:~/tron-web/examples/server#
 

 

이더리움은 개인키로 서명해서  send트렌젝션 한다면

트론은 서버 접속할때 개인키를 하나 들고 있어야되고

서버에서 서명해서 보낼거 같은데 테스텟이 아직 불안해서 그런가 싶기도 하다.

그리고 API 메뉴얼에 "Create an unsigned transaction"으로 되어 있다.

 

참고 사이트 보니 트랜젝션을 만들고 그뒤에 사인을 해서 보낸다.

결국 이더랑 유사하다.

 

테스트넷도 블록 익스프러러가 빨리 만들어져야 될텐데

 

내가 코드를 짜는건지 코드가 나를 짜는건지 모르겠지만 ㅎㅎ

index.js

const TronWeb = require('../../dist/TronWeb.node.js');

const fullNode = 'https://api.shasta.trongrid.io';
const solidityNode = 'https://api.shasta.trongrid.io';
const eventServer = 'https://api.shasta.trongrid.io';
const privateKey = '개인키';

const app = async () => {
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);
    sendTransaction = await tronWeb.transactionBuilder.sendTrx('TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih', 1);
    sendTransaction.raw_data.data = 'hex message';

    const signedTransaction = await tronWeb.trx.sign(sendTransaction);
    console.group('Signed');
    console.log('- Transaction:\n' + JSON.stringify(signedTransaction, null, 2), '\n');
    console.groupEnd(); // no error {raw_data.data = 'hex_message'} Added

    const sendRaw = await tronWeb.trx.sendRawTransaction(signedTransaction); // error
    console.group('Success');
    console.log('- Transaction:\n' + JSON.stringify(sendRaw, null, 2), '\n');
    console.groupEnd();

};
app(); 

 

먼가 되는거 같다.

트랜젝션 쏘기 전에 이제 Sign부터 넣었다.

트론이 이더리움을 배꼈다면 그렇게 만들수 밖에 없다.

이더리움은  개인키로 전자서명하고 공개키를 같이 node에 보낸다.

그래서 서버단에서 PKI검증한다.

트론도 비슷하지 않을까 싶다.

 

 

root@tkpark-VirtualBox:~/tron-web/examples/server# nodejs index.js
Signed
  - Transaction:
  {
    "txID": "c544fb84a26dd202c9e2fdc85663a4ee41401c005c4d994dc0ad81a84b5

40a4d",
    "raw_data": {
      "contract": [
        {
          "parameter": {
            "value": {
              "amount": 1,
              "owner_address": "417b4db2232332c2267271d10c55c126fae6f67de1",
              "to_address": "41b0720a94d13ef83434e1385b543c9291c79a6d14"
            },
            "type_url": "type.googleapis.com/protocol.TransferContract"
          },
          "type": "TransferContract"
        }
      ],
      "ref_block_bytes": "39d1",
      "ref_block_hash": "59ddb3394b45a28e",
      "expiration": 1545113424000,
      "timestamp": 1545113364738,
      "data": "hex message"
    },
    "signature": [
      "b2dbad9bcc00d2ae2624dd1edcfd80e00e303e7a71a6da7c76127f6030b09

cc47b91e9f81                                                                                             cbe26b1dc40bbbf3bdb333245ffa65d117533219680d041675071e900"
    ]
  }

Success
  - Transaction:
  {
    "code": "OTHER_ERROR",
    "message": "6f74686572206572726f72203a206e756c6c"
  }

root@tkpark-VirtualBox:~/tron-web/examples/server# ~

 

 

먼가 올라간거 같은데,,OTHER_ERROR를 토한다.

주문 오류란다. 식당도 아닌데 말이다 ㅋㅋ

 

TronLink에서 출금된 트렌젝션이 없다.

 

먼가 잘못 되었다는거다.  또 다시 삽질하고 추리하자..

소스 그대로 복붙해서 그런지 저 깃허브 에러메세지랑 유사하다.

밑에 해결책이 있을듯,,,,,

 

순서는

 

Build -> Sign -> Send 순서다.

 

저 위에서 소스에서 빨간색 부분 빼고 보내면 된다.

1개 보낼러면 소수점 6개라서 백만 입력 해야 된다.

 

index.js

const TronWeb = require('../../dist/TronWeb.node.js');

const fullNode = 'https://api.shasta.trongrid.io';
const solidityNode = 'https://api.shasta.trongrid.io';
const eventServer = 'https://api.shasta.trongrid.io';
const privateKey = '개인키';

const app = async () => {
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);
    sendTransaction = await tronWeb.transactionBuilder.sendTrx('TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih', 1000000);

    const signedTransaction = await tronWeb.trx.sign(sendTransaction);
    console.group('Signed');
    console.log('- Transaction:\n' + JSON.stringify(signedTransaction, null, 2), '\n');
    console.groupEnd(); // no error {raw_data.data = 'hex_message'} Added

    const sendRaw = await tronWeb.trx.sendRawTransaction(signedTransaction); // error
    console.group('Success');
    console.log('- Transaction:\n' + JSON.stringify(sendRaw, null, 2), '\n');
    console.groupEnd();

};
app(); 

 

실행결과

root@tkpark-VirtualBox:~/tron-web/examples/server# nodejs index.js
Signed
  - Transaction:
  {
    "txID": "59c8d68a939b87180da5ddf78c2f03257e0a6ed682711ae5f77588357c138e34",
    "raw_data": {
      "contract": [
        {
          "parameter": {
            "value": {
              "amount": 1000000,
              "owner_address": "417b4db2232332c2267271d10c55c126fae6f67de1",
              "to_address": "41b0720a94d13ef83434e1385b543c9291c79a6d14"
            },
            "type_url": "type.googleapis.com/protocol.TransferContract"
          },
          "type": "TransferContract"
        }
      ],
      "ref_block_bytes": "423f",
      "ref_block_hash": "d68872a44e72ff02",
      "expiration": 1545119898000,
      "timestamp": 1545119838729
    },
    "signature": [
      "568bba26156139fcd20b3128a5748ae32dba482a308d5f1afdcfbf621316c888e

a529b07a30b90961de27393c9e046e6ef54abed7966db0754af611a824108e800"
    ]
  }

Success
  - Transaction:
  {
    "result": true,
    "transaction": {
      "txID": "59c8d68a939b87180da5ddf78c2f03257e0a6ed682711ae5f77588357c13

8e34"                                                                                             ,
      "raw_data": {
        "contract": [
          {
            "parameter": {
              "value": {
                "amount": 1000000,
                "owner_address": "417b4db2232332c2267271d10c55c126fae6f67de1",
                "to_address": "41b0720a94d13ef83434e1385b543c9291c79a6d14"
              },
              "type_url": "type.googleapis.com/protocol.TransferContract"
            },
            "type": "TransferContract"
          }
        ],
        "ref_block_bytes": "423f",
        "ref_block_hash": "d68872a44e72ff02",
        "expiration": 1545119898000,
        "timestamp": 1545119838729
      },
      "signature": [
        "568bba26156139fcd20b3128a5748ae32dba482a308d5f1

afdcfbf621

316c888ea529b07a30b90961de27393c9e046e6ef54abed7966d

b0754af611

a824108e800"
      ]
    }
  }

root@tkpark-VirtualBox:~/tron-web/examples/server#

 

 

 

에러는 이제 안뜸

 

 

생각해보니 송금하는데 스마트컨트렉도 아니고 메세지를 왜 집어 넣었을가?

트론이 트래픽 작고 수수료 싸다고 무시하는건지

이건 암호화폐 메커니즘의 기본이다.

 

저 글 올린 친구 아직 해결했는지 모르겠다.

 

API도 많이 읽었고 공부 많이 했다. 해결도 했고 천천히 다음진도 나가자

저 API가이드에서 강조하는건 절대 web에서 전자서명 하지 말라는것

 

당연한거지만 Private가 유출될수 있다는 위험성이다.

 

 

 

개발하면서 꼭 명심하자...

 

 

 

 

 

 

'트론' 카테고리의 다른 글

tron-web 분해하기4(getTransactionstoAddress)  (0) 2018.12.19
tron-web 분해하기3(getTransactionsFromAddress)  (0) 2018.12.18
tron-web 분해하기1 (tronWeb.createAccount)  (0) 2018.12.17
tron-web 설치  (0) 2018.12.17
tronbox 설치  (1) 2018.12.17
블로그 이미지

iesay

,