10 dakikadan az
İlk ajan ödemesi
Ergo testnet üzerinde.
Teori yok. Kurulum seremonisi yok. Bir npm paketi, 30 satır, bir komut — ve Ergo testnet gezgininde gerçek bir işlem görürsünüz.
bash
npm install @fleet-sdk/core
Ön Koşullar
- Node.js 18+ yüklü
- Bir testnet adresi (Nautilus cüzdan → Ayarlar → testnet modunda oluşturun)
- testnet.ergofaucet.org adresinden testnet ERG
- 5 dakika kesintisiz odaklanma
01
Fleet SDK yı Yükle
~30 saniyebash
mkdir my-agent && cd my-agent npm init -y npm install @fleet-sdk/core node-fetch
Fleet SDK, Ergo nun resmi TypeScript/JS SDK sıdır. Node.js ve tarayıcılarda çalışır.
02
agent-pay.js oluştur
~2 dakikajavascript
// agent-pay.js
import { TransactionBuilder, OutputBuilder, SAFE_MIN_BOX_VALUE } from "@fleet-sdk/core";
// ── Config ───────────────────────────────────────────────────────────────────
const TESTNET_API = "https://api-testnet.ergoplatform.com";
const YOUR_ADDRESS = "YOUR_TESTNET_ADDRESS"; // paste your testnet address
const RECEIVER_ADDRESS = "3WwbzW6u8hKWBcL1W7kNVMr25s2UHfSBnYtwSHvrRQt7DdPuoXrt"; // testnet receiver
// ── 1. Fetch unspent boxes ────────────────────────────────────────────────────
const res = await fetch(
`${TESTNET_API}/api/v1/boxes/unspent/byAddress/${YOUR_ADDRESS}`
);
const { items: inputs } = await res.json();
// ── 2. Build transaction ──────────────────────────────────────────────────────
const unsignedTx = new TransactionBuilder(await getCurrentHeight())
.from(inputs)
.to(
new OutputBuilder("1000000", RECEIVER_ADDRESS) // 0.001 ERG
)
.sendChangeTo(YOUR_ADDRESS)
.payMinFee()
.build()
.toEIP12Object();
console.log("Unsigned TX:", JSON.stringify(unsignedTx, null, 2));
// → Sign with Nautilus wallet or server-side key, then submit
async function getCurrentHeight() {
const r = await fetch(`${TESTNET_API}/api/v1/info`);
const info = await r.json();
return info.fullHeight;
}Bu script testnet UTxO larınızı getirir, bir işlem oluşturur ve imzasız TX nesnesini çıktılar.
03
Scripti çalıştır
~10 saniyebash
node agent-pay.js
İmzasız işlem JSON unu göreceksiniz. Nautilus (tarayıcı) veya sunucu tarafı bir anahtarla imzalayın, ardından /api/v1/transactions a POST edin.
04
Note (ajan ödemesi) ekle
~5 dakikajavascript
// Note payment — agent pays for an API call
import { TransactionBuilder, OutputBuilder, SByte, SColl } from "@fleet-sdk/core";
const TASK_HASH = "a1b2c3d4..."; // blake2b256 of task output
const noteOutput = new OutputBuilder("5000000", RECEIVER_ADDRESS) // 0.005 ERG
.setAdditionalRegisters({
R4: SColl(SByte, Buffer.from(TASK_HASH, "hex")), // task hash
R5: SByte(await getCurrentHeight() + 100), // expiry: +100 blocks
});
const tx = new TransactionBuilder(await getCurrentHeight())
.from(inputs)
.to(noteOutput)
.sendChangeTo(YOUR_ADDRESS)
.payMinFee()
.build();Bu, temel TX i genişleterek bir Note — görev hash kaydına sahip hamiline ait araç — oluşturur. Alıcı bunu Reserve e karşı itfa eder.
Gezginde TX inizi görün
Gönderdikten sonra işleminiz Ergo testnet gezgininde görünür. TX ID nizi buraya yapıştırın:
https://testnet.ergoplatform.com/transactions/{TX_ID}