Examples

Node.js

Node.js로 Token History API의 GET /klay/transfer를 실행할 때 다음 요청을 보낼 수 있습니다. 예제는 Axios를 사용하며 원하는 HTTP 클라이언트를 사용할 수 있습니다.

const axios = require('axios');
// Use your KAS key pair
const accessKey = "your_kas_access_key";
const secret = "your_kas_secret_accompanied_with_the_provided_access_key";
const eoaAddr = "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; // change this to an address you want to query
const chainId = 1001; // Baobab; for Cypress, use 8217
// Basic auth credential
const credential = Buffer.from(`${accessKey}:${secret}`).toString("base64");
// Make sure your are using TLS
const url = "https://th-api.beta.klaytn.io/v1/klay/transfer";
const headers = {
"Authorization": `Basic ${credential}`,
"Content-Type": "application/json",
"x-krn": `krn:${chainId}:th`,
};
axios.get(url, {
headers: headers, params: {
eoaAddress: eoaAddr
}
}).then(function (response) {
// response['data'] cotains response body
console.log(response['data']);
}).then(function (err) {
if (err) {
console.error("error: " + err)
}
}).then(function () {
// finally
})

Python

Python으로 Token History API의 GET /klay/transfer를 실행합니다. 예제는 HTTP 클라이언트로 requests를 사용하며 다른 라이브러리를 사용할 수 있습니다.

import requests
from requests.auth import HTTPBasicAuth
access_key = 'your_kas_access_key'
secret = 'your_kas_secret_accompanied_with_the_provided_access_key'
# Make sure your are using TLS
url = 'https://th-api.beta.klaytn.io/v1/klay/transfer'
# Change this to an address you want to query
payload = {'eoaAddress': '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'}
# Use 1001 for Baobab; for Cypress, use 8217
headers = {'x-krn': 'krn:1001:th'}
# Use HttpBasicAuth for basic auth
r = requests.get(url, params=payload, headers=headers,
auth=HTTPBasicAuth(access_key, secret))
print(r.status_code, r.text)