Receiving Faucet
What is Faucet?
Faucet์ด๋ ์ง์ญํ๋ฉด ์๋๊ผญ์ง๋ผ๋ ์๋ฏธ๋ก ๋ธ๋ก์ฒด์ธ ์ํ๊ณ์์๋ ํธ๋์ญ์ ์ ์คํํ๊ธฐ ์ํด ์๋์ Native Token์ ์ง์๋ฐ๋ ํ์๋ฅผ ์๋ฏธํฉ๋๋ค. Aptos์์๋ Faucet ํ ๋ฒ์ ์ต๋ 1 APT๋ฅผ ๋ฐ์ ์ ์์ผ๋ฉฐ Devnet์ ๊ฒฝ์ฐ IP๋น ํ๋ฃจ 100ํ, Testnet์ ๊ฒฝ์ฐ IP๋น ํ๋ฃจ 10ํ๋ก ์ ํ๋์ด ์์ต๋๋ค.
์ด ํํ ๋ฆฌ์ผ์ ํตํด ์๋ ๋ด์ฉ์ ๋ฐฐ์ธ ์ ์์ต๋๋ค!
- ์ฌ์ฉ์์ ๊ณ์ ์ Faucet์ ๋ฐ์ ์ ์์ต๋๋ค.
- ์ฌ์ฉ์์ ๊ณ์ ์ ์๋ APT coin์ ์๊ณ ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
- ์ ์ฒด ํํ ๋ฆฌ์ผ ์ฝ๋๋ ์๋ ๋งํฌ๋ฅผ ํตํด ํ์ธํ ์ ์์ต๋๋ค.
Get faucet using SDK
Step 1. ๋ณด์ ํ Account์ address๋ฅผ ์ด์ฉํ์ฌ Faucet์ ๋ฐ๊ณ ์๊ณ ํ์ธํ๊ธฐ
fundAccount ๋ฉ์๋๋ฅผ ์ด์ฉํ์ฌ Account์ Faucet์ ๋ฐ๋ ํจ์๋ฅผ ์์ฑํฉ๋๋ค. ๋ง์ฝ Account๊ฐ ์๋ค๋ฉด Nodit์์ ์ ๊ณตํ๋ ํํ ๋ฆฌ์ผ์ ์งํํด Account ์์ฑ ๋ฐฉ๋ฒ์ ๋ฐฐ์ธ ์ ์์ต๋๋ค.
์๋์ ๊ฐ์ด ์์ฑ ํ ํด๋น ํ์ผ์ ์คํํ์ฌ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํฉ๋๋ค.
// faucet.ts
import {
Aptos,
AptosConfig,
} from "@aptos-labs/ts-sdk";
const config = new AptosConfig({
fullnode: "your_Nodit_Aptos_testnet_node_endpoint",
indexer: "your_Nodit_Aptos_indexer_endpoint",
faucet: "https://faucet.testnet.aptoslabs.com",
});
const aptos = new Aptos(config);
const address = "input_your_account_address";
(async (address : string) => {
try {
const getFaucet = await aptos.fundAccount({
accountAddress: address,
amount: 100_000_000,
});
console.log(getFaucet);
} catch (error) {
console.error(error);
}
})(address);
$ ts-node faucet.ts
์ ์์ ์ผ๋ก ์คํ์ด ๋์๋ค๋ฉด ์๋์ ๊ฐ์ ํธ๋์ญ์ ๋ฐ์ดํฐ๋ฅผ ํ์ธํ ์ ์์ด์ผ ํฉ๋๋ค.
{
version: '5448867634',
hash: '0xf65552c190db9e4783a0de0f3e7410992f42dfe65d21973e229912bb662b1080',
state_change_hash: '0xffc3432d6781ce8d08296563a87a4a52d640270a2372b663da45686c704e3730',
event_root_hash: '0xafdb74074e9a021dff5e66edc00e608b9d47d55b609dec960234f5575a671dbc',
state_checkpoint_hash: null,
gas_used: '13',
success: true,
vm_status: 'Executed successfully',
accumulator_root_hash: '0x28a0d5048cbeccae2c04941a3573bd6b2b226c7eb433e938b7d648694a6c91d3',
changes: [
{
address: '0x1caef4f995a3d7f545d0d246562be15f73b8cace9dca0aea7e610afa947cb3a3',
state_key_hash: '0xf8a1df6b644e81ee241ed29dbb82b456b897daef76239d37a8390ecf48ae881d',
data: [Object],
type: 'write_resource'
},
...
{
state_key_hash: '0x6e4b28d40f98a106a65163530924c0dcb40c1349d3aa915d108b4d6cfc1ddb19',
handle: '0x1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca',
key: '0x0619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935',
value: '0x30df2ed89f88a7940100000000000000',
data: null,
type: 'write_table_item'
}
],
sender: '0x1caef4f995a3d7f545d0d246562be15f73b8cace9dca0aea7e610afa947cb3a3',
sequence_number: '1270787',
max_gas_amount: '500000',
gas_unit_price: '100',
expiration_timestamp_secs: '1721120484',
payload: {
code: {
bytecode: '0xa11ceb0b0500000008010008020804030c150421020523100733500883012006a30114000000010002000301050800030403010002060105010001070002000008000200010403060c050301050001060c01080001030d6170746f735f6163636f756e740a6170746f735f636f696e04636f696e067369676e65720a616464726573735f6f66094170746f73436f696e0762616c616e6365046d696e74087472616e7366657200000000000000000000000000000000000000000000000000000000000000010308a0860100000000000308ffffffffffffffff000001170a0011000c030a03380007010a02170700172304120a000b030a0207001611020b000b010b02110302',
abi: [Object]
},
type_arguments: [],
arguments: [
'0x3a8e4a6d4e3d38329012d48f1703b62314070285ee85c06e5a1e29fcce7d8cab',
'100000000'
],
type: 'script_payload'
},
signature: {
public_key: '0xdcefb58cbf71a655cc7f92f5f0a0d4023d1373f448ea0a69a57e7a303e75df6e',
signature: '0x90ed08b1621ba2067d8c25c510a241672f34541aca4e9147d26bcf7061aab95239d47b5daba97a3e4292adb5d8be8dced2a8a363445659572c7982b06e02aa0b',
type: 'ed25519_signature'
},
events: [
{
guid: [Object],
sequence_number: '1270787',
type: '0x1::coin::DepositEvent',
data: [Object]
},
...
{
guid: [Object],
sequence_number: '0',
type: '0x1::transaction_fee::FeeStatement',
data: [Object]
}
],
timestamp: '1721120469466436',
type: 'user_transaction'
}
๊ธฐ์กด์ ์ฝ๋์ getAccountAPTAmount
๋ฉ์๋๋ฅผ ์ถ๊ฐํ์ฌ ํด๋น ๊ณ์ ์ APT ์๊ณ ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
import {
Aptos,
AptosConfig,
} from "@aptos-labs/ts-sdk";
const config = new AptosConfig({
fullnode: "your_Nodit_Aptos_testnet_node_endpoint",
indexer: "your_Nodit_Aptos_indexer_endpoint",
faucet: "https://faucet.testnet.aptoslabs.com",
});
const aptos = new Aptos(config);
const address = "input_your_account_address";
(async (address : string) => {
try {
const getFaucet = await aptos.fundAccount({
accountAddress: address,
amount: 100_000_000,
});
console.log(getFaucet);
const getBalance = await aptos.getAccountAPTAmount({
accountAddress: address,
});
console.log("My APT Balance :", getBalance);
} catch (error) {
console.error(error);
}
})(address);
My APT Balance : 100000000
Get faucet using Aptos faucet client
Step 2. ๋ณด์ ํ Account์ address๋ฅผ ์ด์ฉํ์ฌ Faucet ๋ฐ๊ธฐ (aptos-faucet-client)
Aptos์์๋ Faucet์ ์ํ ํด๋ผ์ด์ธํธ๋ฅผ ๋ณ๋๋ก ์ ๊ณตํ๊ณ ์์ต๋๋ค. ์ด๋ฅผ ์ด์ฉํ๊ธฐ ์ํด AptosFaucetClient ์ธ์คํด์ค๋ฅผ ์์ฑํ ํ fund
๋ฉ์๋๋ฅผ ์ด์ฉํ์ฌ faucet์ ์์ฒญํฉ๋๋ค.
import {
AptosFaucetClient,
FundRequest,
FundResponse,
} from "@aptos-labs/aptos-faucet-client";
const faucetClient = new AptosFaucetClient({
BASE: "https://faucet.testnet.aptoslabs.com",
});
const address = "input_your_account_address";
(async (address : string) => {
const request: FundRequest = {
amount : 100_000_000,
address,
};
const getFaucet = await faucetClient.fund.fund({ requestBody: request });
console.log(getFaucet);
})(address);
ํด๋น ์ฝ๋๋ฅผ ์คํํ๋ฉด txn_hashes ๋ผ๋ ์ด๋ฆ์ ํ๋์ ํธ๋์ญ์ ํด์๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
{
txn_hashes: [
'<Your_Transaction_Hash>'
],
...
}
Step 1์์ ์์ฑํ APT ์๊ณ ํ์ธ ์ฝ๋๋ฅผ ์ด์ฉํ์ฌ faucet์ ๋ฐ์ ํ ์๊ณ ๋ฅผ ํ์ธํ๋ ๊ธฐ๋ฅ์ ์ถ๊ฐํฉ๋๋ค.
import {
AptosFaucetClient,
FundRequest,
FundResponse,
} from "@aptos-labs/aptos-faucet-client";
const faucetClient = new AptosFaucetClient({
BASE: "https://faucet.testnet.aptoslabs.com",
});
const address = "input_your_account_address"
(async (address : string) => {
const request: FundRequest = {
amount : 100_000_000,
address,
};
const [getFaucet] = await faucetClient.fund.fund({ requestBody: request }).txn_hashes;
console.log(getFaucet);
const getBalance = await aptos.getAccountAPTAmount({
accountAddress: address,
});
console.log("My APT Balance :", getBalance);
})(address);
fund
๋ฉ์๋์ ์๋ต ๋ฐํ ์์ ์ ๋คํธ์ํฌ์์ ํธ๋์ญ์
์ด ์ฒ๋ฆฌ๋ ์ดํ๊ฐ ์๋ ํธ๋์ญ์
์คํ ์์ ์
๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์์ ๊ฐ์ด ์์ฑ ํ ์๊ณ ๋ฅผ ํ์ธํ ๊ฒฝ์ฐ faucet์ ๋ฐ๊ธฐ ์ ๊ณ์ ์ด ๋ณด์ ํ ์๊ณ ๊ฐ ๋ฐํ๋ ์ ์์ต๋๋ค.
์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ๋คํธ์ํฌ์ ํธ๋์ญ์
์ด ์ฒ๋ฆฌ ๋ ๋ ๊น์ง ๋๊ธฐํ ํ ์๋ต์ ๋ฐํํ๋waitForTransaction
๋ฉ์๋๋ฅผ ์ถ๊ฐํด์ผ ํฉ๋๋ค.
//faucet.ts
import { Aptos, AptosConfig } from "@aptos-labs/ts-sdk";
import {
AptosFaucetClient,
FundRequest,
FundResponse,
} from "@aptos-labs/aptos-faucet-client";
const config = new AptosConfig({
fullnode: "your_Nodit_Aptos_testnet_node_endpoint",
indexer: "your_Nodit_Aptos_indexer_endpoint",
});
const aptos = new Aptos(config);
const faucetClient = new AptosFaucetClient({
BASE: "https://faucet.testnet.aptoslabs.com",
});
const address = "your_account_address";
(async (address: string) => {
try {
const request: FundRequest = {
amount: 100_000_000,
address,
};
const [getFaucet] = (await faucetClient.fund.fund({ requestBody: request }))
.txn_hashes;
await aptos.waitForTransaction({
transactionHash: getFaucet,
});
const getBalance = await aptos.getAccountAPTAmount({
accountAddress: address,
});
console.log("My APT Balance :", getBalance);
} catch (error) {
console.error(error);
}
})(address);
$ ts-node faucet.ts
faucet.ts
ํ์ผ์ ์คํํ๋ฉด ํฐ๋ฏธ๋์์ My APT Balance ์๊ณ ๊ฐ ์ถ๊ฐ๋๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค. ์ด๋ ๊ฒ ๋ฐ์ APT๋ฅผ ์ด์ฉํ์ฌ ๋ค๋ฅธ ์ฃผ์๋ก APT๋ฅผ ์ ์กํ๊ฑฐ๋ ํธ๋์ญ์
์คํ ์ Gas Fee๋ก ์ด์ฉํ ์ ์์ต๋๋ค.
My APT Balance : 100000000
- ํ์ธ์ด ๋์ง ์๋๋ค๋ฉด ์์ ์ฝ๋์ ๋ค๋ฅธ ๋ถ๋ถ์ด ์๋์ง ํ์ธํด ๋ณด์ธ์.
- ์์ ์ฝ๋์ ์ฐจ์ด๊ฐ ์๋๋ฐ ๋์ง ์๋์? ์ฌ๊ธฐ[QnA ๋งํฌ]๋ฅผ ํด๋ฆญํ์ฌ QnA๋ก ๋จ๊ฒจ์ฃผ์ธ์!
Aptos๋ ๋งค์ฐ ๋น ๋ฅด๊ฒ ์ ๋ฐ์ดํธ ๋๊ณ ์์ต๋๋ค!
Aptos ์ฌ๋จ์์ ๋ฐฐํฌํ SDK ๋ฒ์ ์ ๋ฐ๋ผ ๋ณ๊ฒฝ๋๋ ์ ์ด ์์ ์ ์์ต๋๋ค. Nodit์ ํญ์ ์ด๋ฅผ ํ์ธํ๊ณ ์์ผ๋ ์์ ์ ๋ฐ๋ผ ์ฝ๋ ๋ณ๊ฒฝ์ผ๋ก ์ธํ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.
Updated 12 days ago