'2018/12/17'에 해당되는 글 3건

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

,