3. Viewing account and transaction information using Web3 Data API
์ด์ ํํ ๋ฆฌ์ผ์ ํตํด ์ค๋งํธ ์ปจํธ๋ํธ๊ฐ ๋ฌด์์ธ์ง ๋ฐฐ์ฐ๊ณ ์ง์ ์ด๋๋ฆฌ์ Holesky์์ ํธ๋์ญ์ ์ ์คํํด ์ค๋งํธ ์ปจํธ๋ํธ๋ฅผ ๋ฐฐํฌํ๊ณ ํธ์ถํด ๋ณด์์ต๋๋ค. ์ด๋ฒ ํํ ๋ฆฌ์ผ์์๋ Nodit Web3 Data API๋ฅผ ์ด์ฉํด ๋ฐฐํฌ๋ฅผ ์ํด ์คํํ ํธ๋์ญ์ ์ ์ ๋ณด์ ์ค๋งํธ ์ปจํธ๋ํธ๋ฅผ ๋ฐฐํฌํ ๊ณ์ ์ ํธ๋์ญ์ ์ ๋ณด๋ฅผ ํ์ธํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
์ด๋ฒ ํํ ๋ฆฌ์ผ์ ์งํํ๊ธฐ ์ํด์๋ Nodit API Key๊ฐ ํ์ํด์!
Nodit API Key๋ Nodit ์ฝ์์ ํ์๊ฐ์ ํ์ฌ ํ๋ํ ์ ์์ต๋๋ค. ์๋ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ Nodit ์ฝ์์ ํ์๊ฐ์ ํ๊ณ ๋ค์ํ ๋ธ๋ก์ฒด์ธ ๋ ธ๋๋ฅผ ์ด์ฉํด ๋ณด์ธ์!
ํธ๋์ญ์
์กฐํ
ํธ๋์ญ์ ์ ํตํด setMessage ํจ์๋ฅผ ์คํํ์ ๋ ๋ค์๊ณผ ๊ฐ์ ํธ๋์ญ์ ์ ๋ณด๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
{
type: 2,
chainId: 17000,
nonce: 13,
maxPriorityFeePerGas: BigNumber { _hex: '0x59682f00', _isBigNumber: true },
maxFeePerGas: BigNumber { _hex: '0x59682f0e', _isBigNumber: true },
gasPrice: null,
gasLimit: BigNumber { _hex: '0x01303d', _isBigNumber: true },
to: '0x4c12Da0413EA27D6Fe3957955940FFBA949C4cdB',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
data: '0x368b87720000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003c4e6f646974206973206f6e65206f66207468652062657374204e6f64652050726f7669646572205365727669636520696e2074686520776f726c642100000000',
accessList: [],
hash: '0xd58046b4ca4558b90312b83b8e1f8bd1dbea870be516239855b93141463dafba',
v: 0,
r: '0xb38d85427e3c4558bbc8cb27b095d57ee828b80fa3345d78d6a1d864f40405f4',
s: '0x43916907718ca24ed6474a7382f383ba338955c754437db2d6985a6a76635c4b',
from: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
confirmations: 0,
wait: [Function (anonymous)]
}
์ด๋ฌํ ํธ๋์ญ์
์ ๋ณด๋ฅผ Nodit Web3 Data API๋ฅผ ์ด์ฉํด์ ํ์ธํ ์ ์์ต๋๋ค. Nodit Web3 Data API ์ค Get Transaction By Hash
API๋ฅผ ์ด์ฉํด ๋์ผํ ํธ๋์ญ์
์ ๋ณด๋ฅผ ํ์ธํด ๋ณด๊ฒ ์ต๋๋ค.
ํ์ ์คํฌ๋ฆฝํธ ํ๊ฒฝ์์ ๊ฐํธํ๊ฒ HTTP ์์ฒญ์ ์ ์กํ๊ธฐ ์ํด axios๋ผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํฉ๋๋ค.
$ npm install axios
axios๋ฅผ ์ค์นํ ํ axios ์ธ์คํด์ค๋ฅผ ์์ฑํด Nodit Web3 Data API๋ฅผ ํธ์ถํฉ๋๋ค. aixos ์ธ์คํด์ค์ ๊ฒฝ์ฐ, baseURL๊ณผ headers๋ฅผ ๋ฏธ๋ฆฌ ์ค์ ํ์ฌ ํธ๋ฆฌํ๊ฒ HTTP ์์ฒญ์ ์ ์กํ ์ ์๊ฒ ํฉ๋๋ค.
// axiosRequest.ts
import axios from "axios";
const noditAPIKey = "your_nodit_api_key";
const axiosInstance = axios.create({
baseURL: "https://web3.nodit.io/v1/ethereum/holesky",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"X-API-KEY": noditAPIKey,
},
});
๊ทธ๋ฆฌ๊ณ ์ฆ์์คํํจ์๋ฅผ ์ด์ฉํด axios ์ธ์คํด์ค๊ฐ Get Transaction By Hash
API๋ฅผ ์คํํ๋ ์ฝ๋๋ฅผ ์์ฑํฉ๋๋ค. Get Transaction By Hash
API๋ ํธ๋์ญ์
ํด์๋ฅผ ํ์ Body Params๋ก ๋ฐ์ต๋๋ค. withDecode๋ฅผ true๋ก ์ค์ ํ ๊ฒฝ์ฐ ํด๋น ํธ๋์ญ์
์ Data ํ๋์ ์
๋ ฅ๋ ๋ฐ์ดํฐ๋ฅผ ๋์ฝ๋ฉ ๋ ๊ฐ์ผ๋ก ํ์ธํ ์ ์์ต๋๋ค.
(async () => {
try {
const txResult = await axiosInstance.post(
"/blockchain/getTransactionByHash",
{
transactionHash:
"0xd58046b4ca4558b90312b83b8e1f8bd1dbea870be516239855b93141463dafba",
withDecode: true,
}
);
console.log(txResult.data);
console.log(txResult.data.decodedInput.args[0]);
} catch (error) {
console.error(error);
}
})();
์ ์ฒด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ํ์ผ์ ์คํํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํด ๋ณด์ธ์!
// axiosRequest.ts
import axios from "axios";
const noditAPIKey = "your_nodit_api_key";
const axiosInstance = axios.create({
baseURL: "https://web3.nodit.io/v1/ethereum/holesky",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"X-API-KEY": noditAPIKey,
},
});
(async () => {
try {
const txResult = await axiosInstance.post(
"/blockchain/getTransactionByHash",
{
transactionHash:
"0xd58046b4ca4558b90312b83b8e1f8bd1dbea870be516239855b93141463dafba",
withDecode: true,
}
);
console.log(txResult.data);
console.log(txResult.data.decodedInput.args[0]);
} catch (error) {
console.error(error);
}
})();
์๋์ ๊ฐ์ด ํธ๋์ญ์ ์ ์ ๋ณด์ ๋์ฝ๋ฉ ๋ ํธ๋์ญ์ ์ Data ํ๋์ ๊ฐ์ ํ์ธํ ์ ์์ต๋๋ค.
{
transactionHash: '0xd58046b4ca4558b90312b83b8e1f8bd1dbea870be516239855b93141463dafba',
transactionIndex: '4',
blockHash: '0x2710f36851312fbe2a20c8afd04b1f34b135e1cf59b0bf8881ee8fc1f91da5b0',
blockNumber: '2319452',
from: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
to: '0x4c12Da0413EA27D6Fe3957955940FFBA949C4cdB',
value: '0',
input: '0x368b87720000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003c4e6f646974206973206f6e65206f66207468652062657374204e6f64652050726f7669646572205365727669636520696e2074686520776f726c642100000000',
functionSelector: '0x368b8772',
decodedInput: {
type: 'function',
name: 'setMessage',
signature: 'setMessage(string)',
args: [ [Object] ]
},
nonce: '13',
gas: '77885',
gasPrice: '1500000007',
maxFeePerGas: '1500000014',
maxPriorityFeePerGas: '1500000000',
gasUsed: '76997',
cumulativeGasUsed: '726811',
effectiveGasPrice: '1500000007',
contractAddress: null,
type: '2',
status: '1',
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
accessList: [],
timestamp: 1726125228
}
// console.log(txResult.data.decodedInput.args[0]);
{
name: 'message',
type: 'string',
value: 'Nodit is one of the best Node Provider Service in the world!'
}
์ด๋๋ฆฌ์ Explorer์์๋ ํธ๋์ญ์ ์ด ํ์ธ๋๋๋ฐ Web3 Data API๋ก๋ ๊ฒฐ๊ณผ๊ฐ ๋ฐํ๋์ง ์์์.
Web3 Data API์ ๊ฒฝ์ฐ, ๋ฐ์ดํฐ ๋ฌด๊ฒฐ์ฑ์ ํ๋ณดํ๊ธฐ ์ํด 6๋ธ๋ก์ด ์ง๋ ๋ณ๊ฒฝ๋์ง ์์ ๋ฐ์ดํฐ๋ฅผ ์ ๊ณตํ๋ ๊ฒ์ ์ ์ฑ ์ผ๋ก ํฉ๋๋ค. ๋ฐ๋ผ์ ๋ธ๋ก์ด ์์ฑ๋ ์งํ API๋ก ์กฐํํ ๊ฒฝ์ฐ ์๋ต์ด ๋ฐํ๋์ง ์์ ์ ์์ผ๋ฉฐ ์ฆ์ ๋ฐ์ดํฐ๋ฅผ ๋ฐํ๋ฐ๊ณ ์ถ๋ค๋ฉด Node API์
eth_getTransactionByHash
API๋ฅผ ์ด์ฉํด ๋ณด์ธ์!
๊ณ์ ์ ์ด์ฉํ ํธ๋์ญ์
์กฐํ
์ด๋ฒ์๋ ๊ณ์ ์ ์ด์ฉํด ํด๋น ๊ณ์ ์ด ์คํํ ํธ๋์ญ์
์ ์กฐํํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. Nodit์ Web3 Data API ์ค Get Transactions By Account
API๋ฅผ ์ด์ฉํฉ๋๋ค. ์ฆ์์คํํจ์์ ๋ด์ฉ์ ์๋์ ๊ฐ์ด ์์ ํฉ๋๋ค.
import axios from "axios";
const noditAPIKey = "your_nodit_api_key";
const axiosInstance = axios.create({
baseURL: "https://web3.nodit.io/v1/ethereum/holesky",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"X-API-KEY": noditAPIKey,
},
});
(async () => {
try {
const txResult = await axiosInstance.post(
"/blockchain/getTransactionsByAccount",
{
accountAddress: "0xEc801CFCF110675F32b593A7f25d09B8f7c6D291",
withDecode: true,
}
);
for (const item of txResult.data.items) {
console.log(item);
}
} catch (error) {
console.error(error);
}
})();
Get Transactions By Account
API๋ accountAddress๋ฅผ ์ธ์๋ก ๋ฐ์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ withDecode๋ฅผ true๋ก ํ์ฌ ๋์ฝ๋ฉ ๋ ํธ๋์ญ์
์ Data ํ๋์ ๊ฐ์ ํ์ธํฉ๋๋ค. ์คํํ๋ฉด ๋ค์๊ณผ ๊ฐ์ด ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
{
transactionHash: '0x269382830d9910b6c80399ef3af87b6217a41caee24a0d3c24e32d72cc56f866',
transactionIndex: '2',
blockHash: '0x2c1c0196f4ae18a7bd48e4c5c4e3328b8026f947839f3b92e137504122463a61',
blockNumber: '2320187',
from: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
to: '0x4c12Da0413EA27D6Fe3957955940FFBA949C4cdB',
value: '0',
input: '0x368b87720000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003d4e6f646974206973206f6e65206f66207468652062657374204e6f64652050726f7669646572205365727669636520696e2074686520776f726c642121000000',
functionSelector: '0x368b8772',
decodedInput: {
type: 'function',
name: 'setMessage',
signature: 'setMessage(string)',
args: [ [Object] ]
},
nonce: '15',
gas: '46015',
gasPrice: '1500000007',
maxFeePerGas: '1500000014',
maxPriorityFeePerGas: '1500000000',
gasUsed: '41100',
cumulativeGasUsed: '526530',
effectiveGasPrice: '1500000007',
contractAddress: null,
type: '2',
status: '1',
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
accessList: [],
timestamp: 1726134900
},
{
transactionHash: '0x80846b0c169656f1bcb390b1286205f792d0ee9a456d320a7703ca8e168225e2',
transactionIndex: '1',
blockHash: '0x914d95b6ca009d9b198cd15beb0e279652fd38cc93ef8925ecbbff7320524087',
blockNumber: '2318601',
from: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
to: '0x4c12Da0413EA27D6Fe3957955940FFBA949C4cdB',
value: '0',
input: '0x368b87720000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f49742069732061206d6573736167650000000000000000000000000000000000',
functionSelector: '0x368b8772',
decodedInput: {
type: 'function',
name: 'setMessage',
signature: 'setMessage(string)',
args: [ [Object] ]
},
nonce: '4',
gas: '31821',
gasPrice: '1500000007',
maxFeePerGas: '1500000014',
maxPriorityFeePerGas: '1500000000',
gasUsed: '31468',
cumulativeGasUsed: '52468',
effectiveGasPrice: '1500000007',
contractAddress: null,
type: '2',
status: '1',
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
accessList: [],
timestamp: 1726114152
},
...
{
transactionHash: '0x65fdeee8c624704070317475543d6b8a59ed0a157e925bc887cd1cb8a6d04470',
transactionIndex: '5',
blockHash: '0x2875c6a946e6b95d21370595739d921a07af4154c74d7f804ea1a6e535506f9d',
blockNumber: '2312751',
from: '0x007aB5199B6c57F7aA51bc3D0604a43505501a0C',
to: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
value: '10000000000000000',
input: '0x',
functionSelector: '0x',
nonce: '88109',
gas: '21000',
gasPrice: '1500000007',
maxFeePerGas: '1500000014',
maxPriorityFeePerGas: '1500000000',
gasUsed: '21000',
cumulativeGasUsed: '753089',
effectiveGasPrice: '1500000007',
contractAddress: null,
type: '2',
status: '1',
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
accessList: [],
timestamp: 1726036116
}
Nodit์ ๊ณ์ ์ด ์คํํ ํธ๋์ญ์ ์ ๋ณด ํ์ธ ์ธ์๋ Internal ํธ๋์ญ์ , ๊ณ์ ์ ๋ค์ Nonce ํ์ธ ๋ฑ ๊ณ์ ๊ณผ ๊ด๋ จ๋ ๋ค์ํ API๋ฅผ ์ ๊ณตํ๊ณ ์์ต๋๋ค. ์๋ ๋งํฌ๋ฅผ ํด๋ฆญํด Nodit์ด ์ ๊ณตํ๋ ๋ค์ํ API๋ฅผ ํ์ธํด ๋ณด์ธ์!
Updated about 1 month ago