ERGO
Meno di 10 minuti

Primo pagamento agente
su Ergo testnet.

Niente teoria. Niente cerimonia di configurazione. Un pacchetto npm, 30 righe, un comando — e vedi una transazione reale sull'explorer Ergo testnet.

bash
npm install @fleet-sdk/core

Prerequisiti

  • Node.js 18+ installato
  • Un indirizzo testnet (creane uno in Nautilus wallet → Impostazioni → Modalità testnet)
  • testnet ERG dal faucet su testnet.ergofaucet.org
  • 5 minuti di concentrazione ininterrotta
01

Installa Fleet SDK

~30 secondi
bash
mkdir my-agent && cd my-agent
npm init -y
npm install @fleet-sdk/core node-fetch

Fleet SDK è l'SDK ufficiale TypeScript/JS per Ergo. Funziona in Node.js e nei browser.

02

Crea agent-pay.js

~2 minuti
javascript
// 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;
}

Questo script recupera i tuoi UTxO testnet, costruisce una transazione e produce l'oggetto TX non firmato.

03

Esegui lo script

~10 secondi
bash
node agent-pay.js

Vedrai il JSON della transazione non firmata. Firmalo con Nautilus (browser) o una chiave lato server, poi POST a /api/v1/transactions.

04

Aggiungi un Note (pagamento agente)

~5 minuti
javascript
// 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();

Questo estende la TX base per creare un Note — uno strumento al portatore con un registro hash del task. Il destinatario lo rimborsa contro una Reserve.

Vedi la tua TX sull'explorer

Dopo l'invio, la tua transazione appare sull'explorer Ergo testnet. Incolla il tuo TX ID qui:

https://testnet.ergoplatform.com/transactions/{TX_ID}

Pronto ad approfondire?

L'avvio rapido ti mette in moto. Il riferimento architetturale completo e il playbook in 7 passaggi ti aspettano.

Follow for daily updates