API 호출 가이드

풀 히스토리 API를 호출하는 방법은 2가지가 있습니다.

1. 라이브러리가 있는 상태에서 API 호출하는 방법

1) Web3.js

const Web3 = require('web3');
const Web3HttpProvider = require('web3-providers-http');
const httpEndpoint = 'FULLHISTORY_ENDPOINT';
const accessToken = 'YOUR_ACCESS_TOKEN';
// Custom Option
const options = {
keepAlive: true,
withCredentials: false,
timeout: 30000,
headers: [
{
name: 'Authorization',
value: accessToken //
}
]
};
// HTTP Provider 생성
const httpProvider = new Web3HttpProvider(httpEndpoint, options);
const web3 = new Web3(httpProvider);
// 이더리움 밸런 조회
web3.eth.getBalance('0x_Ethereum_Address').then(console.log);

2) Web3.py

from web3 import Web3
http_endpoint = 'FULLHISTORY_ENDPOINT'; //1) 풀히스토리 API Endpoint 입력
access_token = 'YOUR_ACCESS_TOKEN'; //2) 발급 받은 Access Token 입력
headres = {
'Authorization': access_token,
'Content-Type': 'application/json'
}
// HTTP Provider 생성
w3 = Web3(Web3.HTTPProvider(http_endpoint, request_kwargs={'headers': headres}))
// 이더리움 밸런스 조회
w3.eth.getBalance('0x_Ethereum_Address')

3) Web3j

import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.methods.response.EthGetBalance;
import org.web3j.protocol.http.HttpService;String httpEndpoint = "FULLHISTORY_ENDPOINT"; //1) 풀히스토리 API Endpoint 입력
String accessToken = "YOUR_ACCESS_TOKEN"; // 2) 발급 받은 Access Token 입력
// HTTP Provider 생성
HttpService httpService = new HttpService(httpEndpoint);
httpService.addHeader("Authorization", accessToken);
Web3j web3 = Web3j.build(httpService);
// 이더리움 밸런스 조회
EthGetBalance balanceResult = web3.ethGetBalance("0x_Ethereum_Address");

2. 라이브러리가 없는 상태에서 API 호출 방법

1)Node.js

const axios = require('axios');
const httpEndpoint = 'https://octet-fullhistory.hexlant.com/v1/ETH';
const accessToken = 'YOUR_ACCESS_TOKEN';
// axios 인스턴스 생성하기
const instance = axios.create({
baseURL: httpEndpoint,
timeout: 1000,
headers: {'Authorization': accessToken}
});const address = 'ADDRESS';
instance.get(`/addresses/${address}/transactions`, {
}).then((response) => {
console.log(response.data);
}, (error) => {
console.log(error);
});

2) Python

import requests
headers = {'Authorization': 'YOUR_ACCESS_TOKEN'}
address = 'ADDRESS'
// Request 요청 생성
r = requests.get('EndPoint/v1/ETH/addresses/' + address + '/transactions', headers=headers)

3) Java

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;String httpEndpoint = "FULLHISTORY_ENDPOINT";
String accessToken = "YOUR_ACCESS_TOKEN";
String address = "ADDRESS";
OkHttpClient client = new OkHttpClient();
// Request 인스턴스 생성하기
Request request = new Request.Builder()
.header("Authorization", accessToken)
.url(httpEndpoint + "addresses/" + address + "/transactions")
.build();try (Response response = client.newCall(request).execute()) {
String body = response.body().string();
}