tron Token Balance (trc10)

트론 2019. 1. 29. 10:45

한 3일 삽질 한거 같은데 잘 안된다.

 

어제 자바스크립트 5만줄짜리 분석해보고 코딩 한줄도 못하고

오늘 다시 TronLink부터 차근 차근 분석 해볼려구 한다.

 

오늘 안에 제발 완료 되면 좋겠다.

 

시간은 잘 가서 좋긴한데 ㅎ

조금 답답한 면도 있다.

 

 

https://apilist.tronscan.org/api/account?address=TRWkuqvtjc6FXsbJhpnJNG7bB6CAwu6dfM

 

결과 json은 아래에서 파싱 하면 된다.

https://jsoneditoronline.org/

 

정말 허무하다.

아무거나 마음에 드는거 쓰면 된다.

router.get('/tokenBalance/:Address',function(req,res,next) {
 const app = async () => {
         try {
                const Add = req.params.Address;
                const gBalance = await tronWeb.trx.getAccount(Add);
                var token = gBalance.assetV2[0].value;
                res.json( { "getBalance  ": token})

                }catch (error) { console.log('Task Failure',error);
                }
        };
app();
});

 

블로그 이미지

iesay

,

TronScan(제작 완료)

트론 2019. 1. 10. 10:29

참고 : https://github.com/tronscan/tronscan-api

 

이더스캔은 이더스캔 API로 잠깐 깔짝 때보고 회사 업무상 트론을 계속 보게

 

되었는데  트랜젝션 조회 트론스캔을 어떻게 접근해야 될지 고민중이다.

 

지금 현재 트론 상황은  token발행 심볼때문에  몇몇 함수가 막혀 있다.

 

그중에 하나인 tronWeb.trx.getTransactionsRelated  도 지금 사용이 불가능다.

1. full node를 동기화시켜서 DB에 넣을지?

2. 특정 Token에 대한 것만 DB에  넣을지?

 

input /output에 대한 결과를 어떻게 사용자에게 보여주는게 좋을지 판단이 안선다.

 

그래서 우선  트론스캔에 있는 tx를 웹에서 파싱해서 한번 넣어보자...

API가 제공안하니 웹파싱해서 넣는다 해도 큰 무리는 없을것이다.

 

https://tronscan.org/#/transaction/51d1994d5d36693299bba3ed3002ca46849922fd80df0446acbd28609948d09d

index.js

var express = require('express');
var router = express.Router();
const TronWeb = require('tronweb');
const fullNode = 'https://api.shasta.trongrid.io';
const solidityNode = 'https://api.shasta.trongrid.io';
const eventServer = 'https://api.shasta.trongrid.io/';
var privateKey = '123';

var mysql = require('mysql');
var connection = mysql.createConnection({
        host: 'localhost',
        post: 3306,
        user: 'tkpark',
        password: '1234',
        database: 'tkpark'
    });
const tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
privateKey
  );
tronWeb.setDefaultBlock('latest');
const nodes = 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)
      res.json( {'result':'connect fail'})
router.get('/createAccount/',function(req,res,next) {
        const account = tronWeb.createAccount();
        account.then(function (account) { const isValid = tronWeb.isAddress(account.address['hex']);
                console.log('- Private Key:',   account.privateKey);
                console.log('- Base58:',        account.address.base58);
                console.log('- Valid: ',        isValid,        '\n');
                account.isValid = isValid;
                res.json( {'result':account.privateKey, '- Base58': account.address.base58});
        });
});
router.get('/getBalance/:Address',function(req,res,next) {
        const app = async () => {
                try {
                        const Add = req.params.Address;
                        const gBalance = await tronWeb.trx.getBalance(Add);
                        const gBandwidth = await tronWeb.trx.getBandwidth(Add);
                        console.log("getBalance : ", gBalance);
                        console.log("getBandwidth : ", gBandwidth);
                        console.log("   ", Add);
                        res.json( { "getBalance  ": gBalance, "getBandwidth": gBandwidth, "123": Add})
                }catch (error) { console.log('Task Failure',error);
                }
        };
        app();
});


router.get('/transactionview',function(req,res,next) {
                try{
                        var Address = req.query.Address;
                        var select_sql = "select *, \"send\" from transactionscan where from_address=? union all select *, \"receive\" from transactionscan where to_address=? order by idx desc;";
                        connection.query(select_sql, [Address, Address], function (err, rows, fields) {
                        if (!err) {
                                var resultdown = JSON.stringify(rows);
                                var TRList = JSON.parse(resultdown);
                                var Result_data = [];
                                for(var i=0; i<TRList.length; i++){
                                        var TR=TRList[i];
                                        var info = {
                                                send: TR.send,
                                                idx: TR.idx,
                                                from_address: TR.from_address,
                                                to_address: TR.to_address,
                                                amount: TR.amount,
                                                txid: "https://shasta.tronscan.org/#/transaction/"+ TR.txid
                                        };
                                        Result_data.push(info);
                                }
                                var result_end={
                                        count: Result_data.length, // count
                                        Result_data: Result_data
                                };
                                console.log(result_end);
                                res.send(result_end);
                                } else {
                                console.log('query error : ' + err);
                                }
                        });
                }catch (error) { console.log('Task Failure',error);
                }

});
router.get('/sendToken',function(req,res,next) {
        const app = async () => {
                try {
                        const gPK = req.query.PK;
                        privateKey = tronWeb.setPrivateKey(gPK);
                        const gvalue = req.query.value;
                        const gsendAddress = await tronWeb.address.fromPrivateKey(gPK);
                        const gtoAddress = req.query.toAddress;
                        var txid = "";
                        var result = "";
                        var insert_sql = "insert into transactionscan (from_address, to_address, amount, txid) values (?, ?, ?, ?)";
                        var select_sql = "select * from transactionscan where txid=?";
                        /*
                        console.log("gPK : ", gPK);
                        console.log("gvalue : ", gvalue);
                        console.log("gsendAddres :", gsendAddress);
                        console.log("gtoAddress : ", gtoAddress);
                        */
                       sendTransaction = await tronWeb.transactionBuilder.sendToken(gtoAddress, gvalue, "1002003", gsendAddress);

                        const signedTransaction = await tronWeb.trx.sign(sendTransaction);
                        const sendRaw = await tronWeb.trx.sendRawTransaction(signedTransaction);
                        result = JSON.stringify(sendRaw, null, 2);
                        var TRList = JSON.parse(result);
                        var txid = TRList.transaction.txID;
                        /*
                        console.log('- Transaction:\n' + TRList.transaction.txID);
                        res.json( { "gPK  ": gPK, "gvalue  ": gvalue, "gsendAddres ": gsendAddress, "gtoAddress": gtoAddress,'- Transaction:n': TRList.transaction.txID, "Transaction\n": JSON.stringify(sendRaw, null, 2)});
                        */

 var params = [gsendAddress, gtoAddress, gvalue, txid];
                        connection.query(insert_sql, params, function (err, rows, fields) {
                        if (!err) {
                                console.log('query error : ' + err);
                                //res.send(err);
                         }
                        });
                        connection.query(select_sql, txid, function (err, rows, fields) {
                        if (!err) {
                                console.log(rows);
                                var resultdown = 'rows : ' + JSON.stringify(rows);

                                res.send(resultdown);
                                } else {
                                console.log('query error : ' + err);
                                }
                        });
                        }catch (error) { console.log('Task Failure',error);
                }
        };
        app();
});

 

module.exports = router;

 

실행결과

 

계좌신청
http://192.168.0.118:3000/createAccount/

 

잔액조회 지갑주소
http://192.168.0.118:3000/getBalance/TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih
http://192.168.0.118:3000/getBalance/TMDBC4DoS1yQCjBgnPBJWnfTZN9rAKBUHc

 

송금
http://192.168.0.118:3000/sendToken?PK=@@@@@&value=@@@@&toAddress=@@@@@@@@@@

송금시 API가 변경되어서 꼭 tronWeb.setPrivateKey로 다시 세팅하고

받는 사람 주소를 인자에 넣어야 된다.

 tronWeb.transactionBuilder.sendTrx(gtoAddress, gvalue, gsendAddress);

 

 

트렌젝선 조회
http://192.168.0.118:3000/transactionjson?Address=TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih

 

 

Mysql DB스키마

CREATE TABLE `transactionscan` (
  `idx` int(11) NOT NULL AUTO_INCREMENT,
  `from_address` varchar(100) NOT NULL COMMENT '보내는 사람 주소',
  `to_address` varchar(100) NOT NULL COMMENT '받는 사람  주소',
  `amount` bigint(20) NOT NULL COMMENT '양',
  `txid` varchar(150) NOT NULL COMMENT '트랜젝션 id',
  `regdate` datetime default current_timestamp,
  PRIMARY KEY (`idx`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='트랜젝션 조회 테이블';

 

MariaDB [tkpark]> desc transactionscan;
+--------------+--------------+------+-----+-------------------+----------------+
| Field        | Type         | Null | Key | Default           | Extra          |
+--------------+--------------+------+-----+-------------------+----------------+
| idx          | int(11)      | NO   | PRI | NULL              | auto_increment |
| from_address | varchar(100) | NO   |     | NULL              |                |
| to_address   | varchar(100) | NO   |     | NULL              |                |
| amount       | bigint(20)   | NO   |     | NULL              |                |
| txid         | varchar(150) | NO   |     | NULL              |                |
| regdate      | datetime     | YES  |     | CURRENT_TIMESTAMP |                |
+--------------+--------------+------+-----+-------------------+----------------+

 

 

 

select *, \"send\" from transactionscan where from_address=? union all select *, \"receive\" from transactionscan where to_address=? order by idx desc

해당 쿼리에 대한 결과다.

 

쿼리구문은 당연히 ?가 들어가는 prepared statement

sql 인젝션 방지까지 된다.

 

마지막 부분 조회할때는 지갑 A, B주소로  서로 송금 해보고

A주소로 조회시 send,

파란색 주소를  트랜젝션 조회하면  send한부분 recieve한 부분 보여진다.

빨간색 주소를 트랜잭션 조회해도  send한부분 recieve한 부분 보여진다.

 

트랜젝션 조회시 tronscan 원본에도 조회 되도록

https://shasta.tronscan.org/#/transaction/
4533bb973d7cd4dccc1805b0e43e2a7b341f0e02d23ab8febbe58b994fb8ee73

링크를 함께 뿌려주고 있다.

 

코드 좀 정리 해서 github 라는놈도 한번 써봐야곘다.

회사에서 필요하는 만큼 빨리 잘 만들었다.

 

Dapp 개발하면서 느끼지만 메인넷은 이더리움과 비트코인과 같이

글로벌한 천재들이 있던지

아니면 트론처럼 직원이 많아야 된다.

web3.js나 tronweb이나 API를 유지보수해야될 인력도 어마 어마하게

필요하기 때문이다.

 

 

 

 

 

블로그 이미지

iesay

,

요청시 계속  Pk와 wallet address를 토하는걸 제작중이다.

계좌 던졌을때 balance와 bandwidth를 조회하는것도 같이 한다.

대역폭은 수수료다 하루에 10번까지 예전에 보낸 기록이 있던 계좌면 무료다

 

 

index.js

var express = require('express');
var router = express.Router();
const TronWeb = require('tronweb');
const fullNode = 'https://api.shasta.trongrid.io';
const solidityNode = 'https://api.shasta.trongrid.io';
const eventServer = 'https://api.shasta.trongrid.io/';
var privateKey = '123';
const tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
privateKey
  );
tronWeb.setDefaultBlock('latest');
const nodes = 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)
      res.json( {'result':'connect fail'})
router.get('/createAccount/',function(req,res,next) {
 const account = tronWeb.createAccount();
 account.then(function (account) { const isValid = tronWeb.isAddress(account.address['hex']);
  console.log('- Private Key:', account.privateKey);
  console.log('- Base58:', account.address.base58);
  console.log('- Valid: ', isValid, '\n');
  account.isValid = isValid;
  res.json( {'result':account.privateKey, '- Base58': account.address.base58});
 });
});
router.get('/getBalance/:Address',function(req,res,next) {
 const app = async () => {
  try {
   const Add = req.params.Address;
   const gBalance = await tronWeb.trx.getBalance(Add);
   const gBandwidth = await tronWeb.trx.getBandwidth(Add);
   console.log("getBalance : ", gBalance);
   console.log("getBandwidth : ", gBandwidth);
   console.log("   ", Add);
   res.json( { "getBalance  ": gBalance, "getBandwidth": gBandwidth, "123": Add})
  }catch (error) { console.log('Task Failure',error);
  }
 };
 app();
});

router.get('/sendToken',function(req,res,next) {
        const app = async () => {
                try {
                        const gPK = req.query.PK;
                        privateKey = gPK;
                        const gvalue = req.query.value;
                        const gtoAddress = req.query.toAddress;

                        console.log("gPK : ", gPK);
                        console.log("gvalue : ", gvalue);
                        console.log("gtoAddress : ", gtoAddress);
                       sendTransaction = await tronWeb.transactionBuilder.sendToken(gtoAddress, gvalue, "1002003", gsendAddress);

                        const signedTransaction = await tronWeb.trx.sign(sendTransaction);
                        const sendRaw = await tronWeb.trx.sendRawTransaction(signedTransaction);
                        console.log('- Transaction:\n' + JSON.stringify(sendRaw, null, 2), '\n');

                        res.json( { "gPK  ": gPK, "gvalue  ": gvalue, "gtoAddress": gtoAddress, "Transaction\n": JSON.stringify(sendRaw, null, 2)});

                }catch (error) { console.log('Task Failure',error);
                }
        };
        app();
});


module.exports = router;

 

 

실행 화면

root@tkpark-VirtualBox:~/project/myapp/routes# yarn start
yarn run v1.12.3
$ node ./bin/www
getBalance :  19997900000
getBandwidth :  5000
    TMDBC4DoS1yQCjBgnPBJWnfTZN9rAKBUHc
GET /getBalance/TMDBC4DoS1yQCjBgnPBJWnfTZN9rAKBUHc 304 610.476 ms - -
- Private Key: AE3F46DE20C1EAF287DDA3CDE20A653031C67517FA87AA4641B271D314821F68
- Base58: TSqkCrLPJVxyuapdY5tjptBKFdR1bVEr5x
- Valid:  true

GET /createAccount/ 200 57.919 ms - 125
- Private Key: F64E51F20F91C6407B9B67A7D98BEA5D81F5F995D652E0AF2C663C4F76ED52B0
- Base58: THYQkYZ7nxWZ9YvMuaSDBYGKcXweTErbMb
- Valid:  true

GET /createAccount/ 200 41.523 ms - 125
getBalance :  19997900000
getBandwidth :  5000
    TMDBC4DoS1yQCjBgnPBJWnfTZN9rAKBUHc
GET /getBalance/TMDBC4DoS1yQCjBgnPBJWnfTZN9rAKBUHc 304 560.224 ms - -
getBalance :  2000000
getBandwidth :  5000
    TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih
GET /getBalance/TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih 304 604.726 ms - -

 

root@tkpark-VirtualBox:~/project/myapp/routes# yarn start
yarn run v1.12.3
$ node ./bin/www
gPK :  @@@@@@@
gvalue :  1000000
gtoAddress :  TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih
- Transaction:
{
  "result": true,
  "transaction": {
    "txID": "651d95843f1a4e62c669550425a1844d800f7670b2071e7

2d10418ec724c4cad",
    "raw_data": {
      "contract": [
        {
          "parameter": {
            "value": {
              "amount": 1000000,
              "owner_address": "4179196b90d1e952c5a43d4847caa

08d50b967c34a",
              "to_address": "41b0720a94d13ef83434e1385b543c9

291c79a6d14"
            },
            "type_url": "type.googleapis.com/protocol.TransferContract"
          },
          "type": "TransferContract"
        }
      ],
      "ref_block_bytes": "49c0",
      "ref_block_hash": "5fff2fda293153a4",
      "expiration": 1547082969000,
      "timestamp": 1547082910093
    },
    "signature": [
      "1af3e48aa97d19a9465e2d56ac3b4541dd33abcbaea0c3dadab3a760c6b

2672c033692fe4454b6f2201d2d8bc4d39c806d84a5a4bfafa95a2e4

075a0aba376b700"
    ]
  }
}

GET /sendToken?PK=03f567e0189e1341a5c8d32817acf7dafcfbb3e2860599d2d4f322ff7b3

247ed&value=1000000&toAddress=TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih 200 742.649 ms - 1118
GET /favicon.ico 404 366.336 ms - 1012

 

 

계좌생성

http://192.168.0.118:3000/createAccount/

 

 

GET트랜젝션에서 지갑주소를 바꿔서 조회해도 잘 동작함

http://192.168.0.118:3000/getBalance/TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih

 

차후  https로 하고 POST로 변경할것이다.

 

send trx 트론 송금

송금은 이전에 작성한 부분이 있어서 쉽게 개발이 가능했다.

 

tron-web 분해하기2(transactionBuilder.sendTrx)

http://iesay.tistory.com/104

보내는 from주소는 개인키에서 추출이 가능하기 때문에 인자를

구지 넣지 않아도 된다.

 

 

http://192.168.0.118:3000/sendToken?PK=개인키&value=1000000&toAddress

=받는사람 주소

 

 

이상으로 nodejs express를 활용한

 

계좌생성, 잔액(대역폭)조회, 송금 API를 제작해 보았다.

 

 

블록체인으로 암호화폐 구현하면서 가장 큰 부분이 이론을 알고 생각을 하면서

코딩을 해야 된다. 이게 좀 많은 초심자들의 장벽이 아닐까 한다.

 

비동기 방식에 대한 이해를 많이 하게 되었다

왜 콜백지옥에 빠지는지 콜백 환경에서 왜 디버깅 하기가 힘든지

실력이 없어서 한 일주일 정도 걸린거 같다.

 

이제 트랜젝션 조회 제작해보자.

 

 

 

 

 

 

 

 

 

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

tron Token Balance (trc10)  (0) 2019.01.29
TronScan(제작 완료)  (0) 2019.01.10
tron-web 분해하기5(createToken)  (0) 2018.12.20
tron-web 분해하기4(getTransactionstoAddress)  (0) 2018.12.19
tron-web 분해하기3(getTransactionsFromAddress)  (0) 2018.12.18
블로그 이미지

iesay

,

테스트넷에 Token 생성  내일 뜯어보자

출처 : https://github.com/TronWatch/Desktop-Wallet/tree/master/app/components/Tokens

API : https://developers.tron.network/v3.0/reference#createtoken

 

 

메인넷은 마법사 보고 따라하면 생성 가능

https://www.youtube.com/watch?v=7cQrkHUijbo

블로그 이미지

iesay

,

참고 : https://tron.network/wallet?lng=kor

        https://github.com/TronWatch/TronLink/blob/master/packages/backgroundScript/services/WalletService/Account.js

 

to, from에서 조회한 내역을 MongoDB에 넣어보자

 

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 = 'abc';

 

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);


const transactions = [];


         let hasMoreTransactions = true;
         let offset = 0;


         while(hasMoreTransactions) {
             const newTransactions = (await tronWeb.trx.getTransactionsRelated("TS4AYYxrF38EA3fDw92mMWbWdFWRJ4VKih", 'all', 90, offset))
                 .map(transaction => {
                     transaction.offset = offset;
                     return transaction;
                 });


             if(!newTransactions.length)
                hasMoreTransactions = false;
             else offset += 90;


             transactions.push(...newTransactions);
         }
         console.log("transactions: ", transactions);

};
app();

 

 

 

 

데이터가 블록으로 넘어오는듯,, 블록을 한번 도 조회 해야 되는데

이더처럼 json형태로 to. from. 컨트렉종류, 금액 이렇게 넘어와야 되는데

트론은 token에 대한 개발이 아직 진행중인걸로 보임

 

테스트넷에 대한 지원도 좀 짜증날 정도로 지원을 안해주고 있음.

async updateTransactions() {
 if(this.updatingTransactions) return;
 this.updatingTransactions = true;
 const transactions = await this.getTransactions();
 const filteredTransactions = transactions .filter(( {
  txID
 }) => ( !Object.keys(this.transactions).includes(txID) && !this.ignoredTransactions.includes(txID) ));
 const mappedTransactions = TransactionMapper.mapAll(filteredTransactions) .filter(( {
  type
 }) => SUPPORTED_CONTRACTS.includes(type));
 const newTransactions = [];
 const manuallyCached = [];
 for (const transaction of mappedTransactions) {
  if(transaction.timestamp) {
   transaction.cached = true;
   newTransactions.push(transaction);
   continue;
  }const txData = await NodeService.tronWeb.trx .getTransactionInfo(transaction.txID);
  if(!txData.id) {
   logger.warn(`Transaction $ {
    transaction.txID
   }has not been cached,
   skipping`);
   continue;
  }// if(!txData.id) {
   // logger.warn(`Transaction ${
    transaction.txID
   }has not been cached`);
 // // StorageService.addPendingTransaction(address,
   transaction.txID);
 // transaction.cached = false; // // this.transactions[
    transaction.txID
   ]= transaction;
 // continue; //
  }// logger.info(`Transaction ${
   transaction.txID
  }has been cached`,
  transaction);
transaction.cached = true;
transaction.timestamp = txData.blockTimeStamp;
transaction.receipt = txData.receipt || false;
transaction.result = txData.contractResult || false;
newTransactions.push(transaction);
manuallyCached.push(transaction.txID);
 }const sortedTransactions = [
  ...Object.values(this.transactions),
  ...newTransactions
 ].sort((a,
 b) => b.timestamp - a.timestamp);
this.transactions = sortedTransactions .slice(0,
 100) .reduce((transactions,
 transaction) => {
  transactions[
   transaction.txID
  ]= transaction;
return transactions;
 },
 {});
manuallyCached.forEach(txID => {
  if(txID in this.transactions) return;
// Transaction is now too old for TronLink (100+) this.ignoredTransactions.push(txID);
 });
this.updatingTransactions = false;
this.save();
}

 

블로그 이미지

iesay

,

개인 트렌젝션 조회

 

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

,

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 = 'PK는 자기꺼 넣습니다.';

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 account = await tronWeb.createAccount();
    const isValid = tronWeb.isAddress(account.address);
    console.group('\nGenerated account');
    console.log('- Private Key:', account.privateKey);
    console.log('- Public Key: ', account.publicKey);
    console.group('Address')
    console.log('- Base58:', account.address);
    console.log('- Hex:   ', account.address);
    console.log('- Valid: ', isValid, '\n')
    console.groupEnd();
    console.groupEnd();
};
app();
 

앞에 설치 후 node ./example/server 실행 해보면 쫙 나오는데

하나 하나 분석해서 뜯어 보도록 하자.

nodejs는 Front쪽인데 ,,, 백엔드쪽 역할을 하다보니

자바스크립트 원래 클라이언트 단에서 실행된다.

 

그러다 보니 동기, 비동기 이거 굉장히 애를 먹인다.

한줄 실행되고 다음줄 실행되어야되는데 ,, 좍 다 실행 시킬려구 하니 문제

그래서 저렇게 동기화 시킬부분은 따로 묶어서 그 역할을 수행 하도록 한다.

파란색 부분이 그 역할을 수행하는 부분이다.

 

소스는 tronWeb.createAccount() 새로운 계정 만들어서 뿌려주는 역할이다.

회원 가입할때 같이 써어서 그 결과값을 DB에 넣으면 된다.


 

 

root@tkpark-VirtualBox:~/tron-web/examples/server# nodejs index.js

Generated account
  - Private Key:

 09DDA582A742199A60240AA0CE4EBEFDEA06D3A7B6CCC339117C46CF6A9A88E3


  - Public Key: 

 04C7E8873084E14483DFABB3FD4C49F934C658A3252C02C936C2B110131EF570

1DA479ED0507219AF05A58AB4F9B875A79F9EA95530378FEE140F4979811451B40
  Address
    - Base58: { base58: 'TPpfzoUb7cqmdr1TbGC3m2zAUkE9URLsy2',
      hex: '4197F48D556BAACA989E636E07A1F71C977FB50B71' }
    - Hex:    { base58: 'TPpfzoUb7cqmdr1TbGC3m2zAUkE9URLsy2',
      hex: '4197F48D556BAACA989E636E07A1F71C977FB50B71' }
    - Valid:  false

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

 

 

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

tron-web 분해하기3(getTransactionsFromAddress)  (0) 2018.12.18
tron-web 분해하기2(transactionBuilder.sendTrx)  (0) 2018.12.18
tron-web 설치  (0) 2018.12.17
tronbox 설치  (1) 2018.12.17
트론 shasta 테스트넷  (0) 2018.12.13
블로그 이미지

iesay

,

tron-web 설치

트론 2018. 12. 17. 15:24

ubuntu-18.04.1-desktop-amd64.iso

버추얼박스는 5.1.38 r122592 버전이다.

 

 

최근 버추얼박스가 vmware보다 더 리소스를 적게 먹는다.

많이 성능이 좋아 졌다.

거의 무료가 유료를 앞질렀다고 보면 된다.

root@tkpark-VirtualBox:~# uname -a
Linux tkpark-VirtualBox 4.15.0-39-generic #42-Ubuntu SMP Tue Oct 23 15:48:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
root@tkpark-VirtualBox:~#
 

 

출처 : https://github.com/tronprotocol/tron-web

 

공식 사이트 대로 슬슬 삽질을 시작해 보자.

 npm install tronweb

git clone https://github.com/tronprotocol/tron-web.git
cd tron-web
yarn
yarn build -d
yarn example

 

 

yarn 버전이 너무 낮아서 안됨 몰라서 GURU개발자 에게 물어봄

root@tkpark-VirtualBox:~/tron-web# ls
dist           LICENSE       scripts  webpack.config.js
examples       package.json  src      yarn-error.log
karma.conf.js  README.md     test     yarn.lock
root@tkpark-VirtualBox:~/tron-web# yarn
00h00m00s 0/0: : ERROR: There are no scenarios; must have at least one.
root@tkpark-VirtualBox:~/tron-web# yarn --version
0.32
root@tkpark-VirtualBox:~/tron-web#
 

 

 

yarn 업데이트를 완료 하고

#curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

#echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

#sudo apt update
#sudo apt install yarn

 4줄이다.

 

root@tkpark-VirtualBox:~/tron-web# yarn --version
yarn install v1.12.3

위에 순서대로 yarn, build , example도 실행해 본다.

 

root@tkpark-VirtualBox:~/tron-web# yarn example
yarn run v1.12.3
$ node ./examples/server
Error: fullNode is not connected
Error: solidityNode is not connected
Error: eventServer is not connected

노드는 알아서 잘 적어 주면 된다.

 

vi /examples/server/index.js

const fullNode = 'https://api.shasta.trongrid.io';
const solidityNode = 'https://api.shasta.trongrid.io';
const eventServer = 'https://api.shasta.trongrid.io';
const privateKey = 'Tron링크 계좌 만들어서 PK입력'; 

 

node ./examples/server/ 실행결과

      "id": "1000009"
    },
    {
      "owner_address": "410c7c4f2e280aa73561efe5b92355cc12a150f566",
      "name": "CoconutToken",
      "abbr": "FTKN",
      "total_supply": 900000000,
      "frozen_supply": [
        {
          "frozen_amount": 5,
          "frozen_days": 1
        }
      ],
      "trx_num": 1,
      "num": 1,
      "start_time": 1544511604212,
      "end_time": 1547103604211,
      "description": "Useless utility token",
      "url": "https://google.com",
      "id": "1000002"
    }
  ]

 

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

 

 

 

 

 

 

 

참고 사이트

https://github.com/tronprotocol/Documentation/blob/master/TRX/Tron-http.md

 

명령어 하나 하나 실행해서 해당 명령어가 멀 뜻하는지 판단

curl -X POST  https://api.trongrid.io/walletsolidity/getaccount -d '{"address":

 "41E552F6487585C2B58BC2C9BB4492BC1F17132CD0"}'

root@tkpark-VirtualBox:~/tron-web# curl -X POST  https://api.trongrid.io/walletsolidity/getaccount -d '{"address": "41E552F6487585C2B58BC2C9BB4492BC1F17132CD0"}' | more
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
{"account_name": "636363797979636363","address": "41e552f6487585c2b58bc2c9bb4492
bc1f17132cd0","balance": 10085289,"asset": [{"key": "TRX","value": 1},{"key": "D
EX","value": 0},{"key": "Kitty","value": 0},{"key": "SEED","value": 0},{"key": "
WIN","value": 0},{"key": "Perogies","value": 0},{"key": "TRXTestCoin","value": 0
},{"key": "ofoBike","value": 7},{"key": "Skypeople","value": 0},{"key": "OnePiec
e","value": 0},{"key": "ZZZDOGETRXZZ","value": 0},{"key": "IGG","value": 0},{"ke
y": "Messenger","value": 0},{"key": "justinsuntron","value": 0},{"key": "Bitcoin
100 ","value": 0},{"key": "bittorrent","value": 0},{"key": "IPFS","value": 33},{"key
 

 

 

 

 

트론 개발자 웹사이트

https://www.trongrid.io/

 

oot@tkpark-VirtualBox:~# tronbox
Tronbox v2.2.3-prev.0 - a development framework for tronweb

Usage: tronbox <command> [options]

Commands:
  init     Initialize new and empty tronBox project
  compile  Compile contract source files
  migrate  Run migrations to deploy contracts
  deploy   (alias for migrate)
  build    Execute build pipeline (if configuration present)
  test     Run JavaScript and Solidity tests
  console  Run a console with contract abstractions and commands available
  create   Helper to create new contracts, migrations and tests
  watch    Watch filesystem for changes and rebuild the project automatically
  serve    Serve the build directory on localhost and watch for changes
  exec     Execute a JS module within this tronBox environment
  unbox    Download a tronbox Box, a pre-built tronbox project
  version  Show version number and exit

See more at http://tronboxframework.com/docs

 

응답 결과

curl -G https://api.trongrid.io/wallet/getnowblock 

 

1544596134000,
"fee_limit":6000000,
"timestamp":1544596079147
}
},
{
"ret":[
{
 "contractRet":"SUCCESS"
}
],
"signature":[
"4ba313dd2cd877286d2e2d6a5c987367f60db72d6061248c822959ee8b88980bf8eda99829de336b0f333621976f1f6c38c57babd040ca3a8caccfd91c8efa7500"
],
"txID":"402747a4056cf30e5a062da58ddcdfb2f76643de45ceedbb23a6c84f992f6105",
"raw_data":{
"contract":[
 {
  "parameter":{
   "value":{
    "data":"a3082be900000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001",
    "owner_address":"416b856cb82ad984b5ca5ab6d0a48c550574c4901d",
    "contract_address":"412ec5f63da00583085d4c2c5e8ec3c8d17bde5e28",
    "call_value":550000000
   },
   "type_url":"type.googleapis.com/protocol.TriggerSmartContract"
  },
  "type":"TriggerSmartContract"
 }
],
"ref_block_bytes":"5a0f",
"ref_block_hash":"bddd829263d1947e",
"expiration":1544596134000,
"fee_limit":6000000,
"timestamp":1544596078871
}
},
{
"ret":[
{
 "contractRet":"SUCCESS"
}
],
"signature":[
"9fa491d3b5eb10fa5c96969d0a223e0dcffc45ac71e50e30bca125396f9a8da5422940b0b1f6832436a4fc7286d5ffe1447381ab4616ef6d337dc3d91be41b6400"
],
"txID":"a098d414205db9c9a83daefc71f6a7bb24f7484210d1bd11d3a90dc5fd48af94",
"raw_data":{
"contract":[
 {
  "parameter":{
   "value":{
    "data":"a3082be900000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001",
    "owner_address":"4131e1ec8054b56a857e970656a4f16a95e3cfa4b7",
    "contract_address":"412ec5f63da00583085d4c2c5e8ec3c8d17bde5e28",
    "call_value":1200000000
   },
   "type_url":"type.googleapis.com/protocol.TriggerSmartContract"
  },
  "type":"TriggerSmartContract"
 }
],
"ref_block_bytes":"5a0f",
"ref_block_hash":"bddd829263d1947e",
"expiration":1544596134000,
"fee_limit":6000000,
"timestamp":1544596079403
}
}
]
}

 

 

 

 

 

 

 

 

 

 

 

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

tron-web 분해하기2(transactionBuilder.sendTrx)  (0) 2018.12.18
tron-web 분해하기1 (tronWeb.createAccount)  (0) 2018.12.17
tronbox 설치  (1) 2018.12.17
트론 shasta 테스트넷  (0) 2018.12.13
tron 파이썬 모듈  (0) 2018.12.13
블로그 이미지

iesay

,

tronbox 설치

트론 2018. 12. 17. 10:34

출처 : https://developers.tron.network/docs/tron-box-user-guide

동영상 보고 따라해보았는데  결과가 잘 안나온다.

테스트넷이든 메인넷이든 아직 안정화 될러면 시간이 조금 필요 한듯하다.

 

NPM tronbox 설치

npm install -g tronbox 

 

tutorial 디렉토리 생성

mkdir tutorial 

cd tutorial

 

sample coin 다운로드

 root@tkpark-VirtualBox:~/tuto# tronbox unbox metacoin
Downloading...
Unpacking...
Setting up...
Unbox successful. Sweet!

Commands:

  Compile:        tronbox compile
  Migrate:        npm run migrate
  Test contracts: tronbox test
  Run dev server: npm run dev
root@tkpark-VirtualBox:~/tuto#

 

contracts, migrations 파일 내용 확인

 

약간의 버그가 있어 보이지만,,, 파일 내용을 수정해도 development를 바라보는거

같아서  테스트 서버 shasta 내용을 development쪽으로 복사 해줘라,,,

tronbox.js 내용 편집  TronLink에서 테스트 서버 shasta 발급된 개인키 입력

 

   module.exports = {
  networks: {
    development: {
      // For trontools/quickstart docker image
      privateKey: 'shasta 발급된 개인키 ',
      consume_user_resource_percent: 30,
      fee_limit: 100000000,

      // Requires TronBox 2.1.9+ and Tron Quickstart 1.1.16+
      // fullHost: "http://127.0.0.1:9090",

      // The three settings below for TronBox < 2.1.9
      fullNode: "https://api.shasta.trongrid.io",
      solidityNode: "https://api.shasta.trongrid.io",
      eventServer: "https://api.shasta.trongrid.io",


      network_id: "2"
    }, 

 

tronbox-config.js  development테스트넷 입력

module.exports = {"development"};

 

compile  Compile contract source files

root@tkpark-VirtualBox:~/tuto# tronbox compile
Compiling ./contracts/ConvertLib.sol...
Compiling ./contracts/MetaCoin.sol...
Compiling ./contracts/Migrations.sol...

Compilation warnings encountered:

Warning: This is a pre-release compiler version, please do not use it in production.

Writing artifacts to ./build/contracts

 

 

migrate  Run migrations to deploy contracts

root@tkpark-VirtualBox:~/tuto# tronbox migrate --reset
Using network 'development'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  Migrations:
    (base58) TKoohGjpDNLJKka47nFAbkLDBReRV3Vbev
    (hex) 416bea0f0a7b48200852e0a83342c87580d69dc042
Saving successful migration to network...
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying ConvertLib...
  ConvertLib:
    (base58) TTFLhejo2BabkmjLBAVSeCHs2WCde3iRyM
    (hex) 41bd8738a33c2e2739aaca24e96f1a7901f85fa038
  Linking ConvertLib to MetaCoin
  Deploying MetaCoin...
  MetaCoin:
    (base58) TRGeHatnpxB6g8GmAdDMgjyFzRQR9u7T8J
    (hex) 41a7d6109dc1284b5c20f041c35ab03729bd64def8
Saving successful migration to network...
Saving artifacts...
root@tkpark-VirtualBox:~/tuto#
 

 

test 디렉토리로 이동

oot@tkpark-VirtualBox:~/tuto# cd test
root@tkpark-VirtualBox:~/tuto/test# ls
helpers  metacoin.js
root@tkpark-VirtualBox:~/tuto/test# vi metacoin.js
 

 

 

metacoin.js 파일 편집  vi에서 set nu해서 31번째 줄에 추가 

     it("should put 10000 MetaCoin in the first account", async function () {
    const instance = await MetaCoin.deployed();
    console.log(instance.address);
    const balance = await instance.getBalance(accounts[0], {from: accounts[0]});
    assert.equal(balance, 10000, "10000 wasn't in the first account");
  });

  

 

 

tronbox test

root@tkpark-VirtualBox:~/tuto/test# tronbox test
Using network 'development'.

Deploying contracts to development network...

Warning: This version does not support tests written in Solidity.

Preparing Javascript tests (if any)...


  Contract: MetaCoin

YOUR ATTENTION, PLEASE.]
To test MetaCoin you should use Tron Quickstart (https://github.com/tronprotocol/docker-tron-quickstart) as your private network.
Alternatively, you must set your own accounts in the "before" statement in "test/metacoin.js".

      1) should verify that there are at least three available accounts
    ✓ should verify that the contract has been deployed by accounts[0] (482ms)
41f15ced9d571f1b43346c3e2bde233f797a948f5a
    ✓ should put 10000 MetaCoin in the first account (460ms)
Sleeping for 1 second... Slept.
    ✓ should call a function that depends on a linked library (1779ms)
    2) should send coins from account 0 to 1
    3) should send coins from account 1 to 2


  3 passing (3s)
  3 failing
 1) Contract: MetaCoin
       should verify that there are at least three available accounts:

      AssertionError: expected false to be true
      + expected - actual

      -false
      +true

      at Context.<anonymous> (metacoin.js:21:12)
      at TestRunner.startTest (/usr/local/lib/node_modules/tronbox/build/webpack:/packages/truffle-core/lib/testing/testrunner.js:106:1)
      at Context.<anonymous> (/usr/local/lib/node_modules/tronbox/build/webpack:/packages/truffle-core/lib/test.js:213:1)

  2) Contract: MetaCoin
       should send coins from account 0 to 1:

      accounts[1] does not exist. Use Tron Quickstart!
      + expected - actual

      -false
      +true

      at Context.<anonymous> (metacoin.js:46:12)
      at TestRunner.startTest (/usr/local/lib/node_modules/tronbox/build/webpack:/packages/truffle-core/lib/testing/testrunner.js:106:1)
      at Context.<anonymous> (/usr/local/lib/node_modules/tronbox/build/webpack:/packages/truffle-core/lib/test.js:213:1)

  3) Contract: MetaCoin
       should send coins from account 1 to 2:

      accounts[1] and/or accounts[2] do not exist. Use Tron Quickstart!
      + expected - actual

      -false
      +true

      at Context.<anonymous> (metacoin.js:61:12)
      at TestRunner.startTest (/usr/local/lib/node_modules/tronbox/build/webpack:/packages/truffle-core/lib/testing/testrunner.js:106:1)
      at Context.<anonymous> (/usr/local/lib/node_modules/tronbox/build/webpack:/packages/truffle-core/lib/test.js:213:1)

 

 

 

제대로 올라 간건지 모르겠다.

https://tronscan.org/#/tools/tron-convert-tool

빨간 부분을  아래 사이트에서 Ascii코드에 입력하고 인코딩 시켜 준다.

Base58_hexstring을 선택한다.

 

 

 

 

 

 

 

 

 

GET인자 바꾸어서 크롬에서 접속해보면 아무것도 없다 ㅋㅋ

 https://api.shasta.trongrid.io/event/contract/

sXHwS5pcWLYVdxtTES3gZXADuiwzhVob8JUfRQgLfyz6UQRAKM3EuHV1J

 

TronLink에서 테스트 TRX는 소모된거 같고,, 트렌젝션에 기록도 있다.

 

 

트론 shasta테스트넷  블록익스플러러가 덜 만들어서

제대로 올라간건지 아닌건지 ,,

 

아직 트론은 개발중인거 같다.

 

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

tron-web 분해하기1 (tronWeb.createAccount)  (0) 2018.12.17
tron-web 설치  (0) 2018.12.17
트론 shasta 테스트넷  (0) 2018.12.13
tron 파이썬 모듈  (0) 2018.12.13
트론 노드구축  (0) 2018.12.11
블로그 이미지

iesay

,