steem.js 라이브러리를 이용하면 스팀잇에서 포스팅과 보팅을 포함한 대부분의 기능은 할 수 있습니다.
깃허브(https://github.com/steemit/steem-js/)에 steem.js의 소스코드와 문서 및 예제가 있으나 설명이 친절하지는 않습니다.
더군다나 node.js는 npm이라는 패키지 관리자를 통해 간단한 명령으로 라이브러리를 자신의 PC에 설치할 수 있기 때문에 깃허브에서 steem.js를 다운로드 받아 저장할 일은 없습니다.
첫번째 강좌는 node.js (설치파일: https://nodejs.org/ko/)를 설치한 커맨드 창에서 'npm install steem'를 실행시킨 상태를 전제로 가장 간단한 예제를 실행해 보겠습니다.
프로그램 소스코드를 작성/수정하는 편집기는 메모장에서부터 전용 프로그램까지 다양하지만 저는 visual studio code라는 MS의 무료 소프트웨어를 사용합니다.
1단계
빈 파일(test.js)을 생성합니다.
2단계
다음과 같이 steem.js 라이브러리를 로드 한 후, steem 패키지에 있는 getAccounts 함수로 스팀잇 유저 Dan과 Ned의 계정정보를 조회하는 코드를 작성합니다.
getAccounts 함수의 마지막 인자는 아래의 세줄은 getAccounts함수가 실행된 후 그 결과를 처리하는 소위 callback함수로서 javascript 특유의 프로그래밍 기법입니다.
, function(err, response){
console.log(err, response);
}
이 콜백함수의 기능은 err (에러)결과나 response(응답)결과를 콘솔(모니터 등)에 출력하는 역할을 합니다.
3단계
위 코드를 test.js 파일에 저장한 후 javascript를 지원하는 편집기에서 '실행' 메뉴를 선택하거나 윈도우 명령프롬프트에서 'node test.js'를 타이핑하여 실행합니다.
위 과정을 모두 수행하고 나면 다음과 같이 스팀잇 서버에서 두 사람의 계정정보를 javascript에서 자주 사용하는 JSON 형식으로 응답을 줍니다.
결과확인
steeemd.com에서 조회되는 계정정보과 거의 같은 것을 보실 수 있습니다.
Debugging with legacy protocol because Node.js v6.11.0 was detected.
'C:\Program Files\nodejs\node.exe' test.js
null [ { id: 497,
name: 'ned',
owner: { weight_threshold: 1, account_auths: [], key_auths: [Object] },
active: { weight_threshold: 1, account_auths: [], key_auths: [Object] },
posting: { weight_threshold: 1, account_auths: [], key_auths: [Object] },
memo_key: 'STM6sUWU9dtss1N8m7tQfUt7PacNHACrt3jBZNtkYkMMBv3e4CH3p',
json_metadata: '{"profile":{"profile_image":"https://s32.postimg.org/oix1wvfp1/ned_steem_steemit.jpg","location":"A vision in a dream.","name":"ned"}}',
proxy: '',
last_owner_update: '2017-03-02T00:20:39',
last_account_update: '2017-03-16T17:47:57',
created: '2016-03-31T14:21:45',
mined: false,
owner_challenged: false,
active_challenged: false,
last_owner_proved: '1970-01-01T00:00:00',
last_active_proved: '1970-01-01T00:00:00',
recovery_account: 'steem',
last_account_recovery: '1970-01-01T00:00:00',
reset_account: 'null',
comment_count: 0,
lifetime_vote_count: 0,
post_count: 634,
can_vote: true,
voting_power: 9800,
last_vote_time: '2017-08-16T16:40:33',
balance: '581951.410 STEEM',
savings_balance: '0.000 STEEM',
sbd_balance: '5716.744 SBD',
sbd_seconds: '14383766366907',
sbd_seconds_last_update: '2017-08-22T16:42:30',
sbd_last_interest_payment: '2017-07-24T13:14:15',
savings_sbd_balance: '1249.949 SBD',
savings_sbd_seconds: '0',
savings_sbd_seconds_last_update: '2017-01-01T19:19:27',
savings_sbd_last_interest_payment: '2017-01-01T19:19:27',
savings_withdraw_requests: 0,
reward_sbd_balance: '74.059 SBD',
reward_steem_balance: '0.000 STEEM',
reward_vesting_balance: '595795.837531 VESTS',
reward_vesting_steem: '288.109 STEEM',
vesting_shares: '7344140982.676874 VESTS',
delegated_vesting_shares: '7203414925.000000 VESTS',
received_vesting_shares: '0.000000 VESTS',
vesting_withdraw_rate: '0.000000 VESTS',
next_vesting_withdrawal: '1969-12-31T23:59:59',
withdrawn: 0,
to_withdraw: 0,
withdraw_routes: 0,
curation_rewards: 734347064,
posting_rewards: 8175663,
proxied_vsf_votes: [ '912262787320591', 0, 0, 0 ],
witnesses_voted_for: 0,
average_bandwidth: '6235789132',
lifetime_bandwidth: '3588037000000',
last_bandwidth_update: '2017-08-23T06:40:33',
average_market_bandwidth: 1060000000,
lifetime_market_bandwidth: '112620000000',
last_market_bandwidth_update: '2017-08-11T13:52:15',
last_post: '2017-08-23T06:40:33',
last_root_post: '2017-08-05T01:48:12',
vesting_balance: '0.000 STEEM',
reputation: '41382423390591',
transfer_history: [],
market_history: [],
post_history: [],
vote_history: [],
other_history: [],
witness_votes: [],
tags_usage: [],
guest_bloggers: [] },
{ id: 496,
name: 'dan',
owner: { weight_threshold: 1, account_auths: [], key_auths: [Object] },
active: { weight_threshold: 1, account_auths: [], key_auths: [Object] },
posting: { weight_threshold: 1, account_auths: [], key_auths: [Object] },
memo_key: 'STM7qtpUZfaHwyJk9ZwvXH3EsAxJcYWY4913Vj6xVWkskM8SRV2Ub',
json_metadata: '',
proxy: '',
last_owner_update: '2016-07-15T19:25:21',
last_account_update: '2016-07-15T19:27:51',
created: '2016-03-31T14:21:39',
mined: false,
owner_challenged: false,
active_challenged: false,
last_owner_proved: '1970-01-01T00:00:00',
last_active_proved: '1970-01-01T00:00:00',
recovery_account: 'steem',
last_account_recovery: '1970-01-01T00:00:00',
reset_account: 'null',
comment_count: 0,
lifetime_vote_count: 0,
post_count: 411,
can_vote: true,
voting_power: 8153,
last_vote_time: '2017-08-21T01:10:57',
balance: '869424.190 STEEM',
savings_balance: '0.000 STEEM',
sbd_balance: '782.896 SBD',
sbd_seconds: '334524748026',
sbd_seconds_last_update: '2017-08-23T02:38:12',
sbd_last_interest_payment: '2017-08-18T03:50:03',
savings_sbd_balance: '0.000 SBD',
savings_sbd_seconds: '0',
savings_sbd_seconds_last_update: '1970-01-01T00:00:00',
savings_sbd_last_interest_payment: '1970-01-01T00:00:00',
savings_withdraw_requests: 0,
reward_sbd_balance: '2.234 SBD',
reward_steem_balance: '0.000 STEEM',
reward_vesting_balance: '428470.282436 VESTS',
reward_vesting_steem: '207.600 STEEM',
vesting_shares: '7287739184.310816 VESTS',
delegated_vesting_shares: '0.000000 VESTS',
received_vesting_shares: '0.000000 VESTS',
vesting_withdraw_rate: '662521744.028256 VESTS',
next_vesting_withdrawal: '2017-08-30T01:41:15',
withdrawn: '1325043488056512',
to_withdraw: '8612782672367328',
withdraw_routes: 0,
curation_rewards: 91504500,
posting_rewards: 46019625,
proxied_vsf_votes: [ 0, 0, 0, 0 ],
witnesses_voted_for: 23,
average_bandwidth: '7054762922',
lifetime_bandwidth: '624143000000',
last_bandwidth_update: '2017-08-22T21:38:48',
average_market_bandwidth: 1550000000,
lifetime_market_bandwidth: '40610000000',
last_market_bandwidth_update: '2017-05-30T14:50:57',
last_post: '2017-08-22T21:38:48',
last_root_post: '2017-08-01T15:27:24',
vesting_balance: '0.000 STEEM',
reputation: '84569983600326',
transfer_history: [],
market_history: [],
post_history: [],
vote_history: [],
other_history: [],
witness_votes:
[ 'arhag',
'au1nethyb1',
'bhuz',
'boatymcboatface',
'chitty',
'clayop',
'complexring',
'datasecuritynode',
'delegate.lafona',
'gtg',
'ihashfury',
'joseph',
'liondani',
'masteryoda',
'pfunk',
'pharesim',
'riverhead',
'roadscape',
'steempty',
'steemychicken1',
'theprophet0',
'wackou',
'xeldal' ],
tags_usage: [],
guest_bloggers: [] } ]
첫번째 강좌는 여기까지입니다~