Menos de 10 minutos
Primer pago de agente
en Ergo testnet.
Sin teoría. Sin ceremonia de configuración. Un paquete npm, 30 líneas, un comando — y ves una transacción real en el explorador de Ergo testnet.
bash
npm install @fleet-sdk/core
Prerrequisitos
- Node.js 18+ instalado
- Una dirección testnet (crear en Nautilus wallet → Configuración → Modo testnet)
- testnet ERG del faucet en testnet.ergofaucet.org
- 5 minutos de concentración ininterrumpida
01
Instalar Fleet SDK
~30 segundosbash
mkdir my-agent && cd my-agent npm init -y npm install @fleet-sdk/core node-fetch
Fleet SDK es el SDK oficial de TypeScript/JS para Ergo. Funciona en Node.js y navegadores.
02
Crear agent-pay.js
~2 minutosjavascript
// 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;
}Este script obtiene tus UTxO de testnet, construye una transacción y genera el objeto TX sin firmar.
03
Ejecutar el script
~10 segundosbash
node agent-pay.js
Verás el JSON de la transacción sin firmar. Fírmalo con Nautilus (navegador) o una clave del servidor, luego POST a /api/v1/transactions.
04
Agregar un Note (pago de agente)
~5 minutosjavascript
// 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();Esto extiende la TX básica para crear un Note — un instrumento al portador con un registro de hash de tarea. El receptor lo redime contra un Reserve.
Ver tu TX en el explorador
Después de enviar, tu transacción aparece en el explorador de Ergo testnet. Pega tu TX ID en:
https://testnet.ergoplatform.com/transactions/{TX_ID}