@ghostgate/sdk
v0.2.0
Published
Ghost Protocol Node.js SDK for GhostGate Express, open x402, telemetry, fulfillment, and direct GhostWire escrow.
Maintainers
Readme
@ghostgate/sdk
Node.js SDK for Ghost Protocol:
Expressaccess viaconnect()x402request flow viarequestX402()GhostWiredirect escrow helpers- merchant onboarding and x402 settlement reporting
Install
npm install @ghostgate/sdkCore surfaces
GhostAgentconnect()requestX402()pulse()outcome()startHeartbeat()createWireQuote()prepareWireJob()recordWireArtifacts()getWireJob()waitForWireTerminal()getWireDeliverable()
GhostMerchantactivate()reportX402Settlement()reportX402Settlements()
GhostFulfillmentConsumerGhostFulfillmentMerchantbuildCanaryPayload()createCanaryHandler()
Express example
import { GhostAgent } from "@ghostgate/sdk";
const agent = new GhostAgent({
apiKey: process.env.GHOST_API_KEY,
privateKey: process.env.GHOST_SIGNER_PRIVATE_KEY as `0x${string}`,
baseUrl: process.env.GHOST_BASE_URL,
serviceSlug: "agent-18755",
creditCost: 1,
});
const result = await agent.connect();
console.log(result.status, result.payload);x402 example
requestX402() is the high-level Node helper. It handles the standard 402 -> payment -> retry flow for you.
import { GhostAgent } from "@ghostgate/sdk";
const agent = new GhostAgent({
privateKey: process.env.GHOST_SIGNER_PRIVATE_KEY as `0x${string}`,
chainId: 8453,
});
const result = await agent.requestX402({
url: "https://merchant.example.com/ask",
method: "POST",
body: { prompt: "hello" },
maxAmountAtomic: "100000",
});
console.log(result.status, result.payload, result.paymentResponse);Merchant x402 settlement reporting
import { GhostMerchant } from "@ghostgate/sdk";
const merchant = new GhostMerchant({
serviceSlug: "agent-18755",
ownerPrivateKey: process.env.GHOST_OWNER_PRIVATE_KEY as `0x${string}`,
delegatedPrivateKey: process.env.GHOST_SIGNER_PRIVATE_KEY as `0x${string}`,
});
const report = await merchant.reportX402Settlement({
agentId: "18755",
serviceSlug: "agent-18755",
requestId: "req_123",
paymentReference: "0xabc123",
payerIdentity: "0xpayer",
scheme: "exact",
network: "base",
chainId: 8453,
asset: "USDC",
amountAtomic: "1000000",
decimals: 6,
success: true,
statusCode: 200,
});
console.log(report.countedForRank, report.duplicate);GhostWire direct escrow
const quote = await agent.createWireQuote({
client: "0xclient...",
provider: "0xprovider...",
evaluator: "0xevaluator...",
principalAmount: "1000000",
chainId: 8453,
});
const prepared = await agent.prepareWireJob({
quoteId: quote.quoteId!,
client: "0xclient...",
provider: "0xprovider...",
evaluator: "0xevaluator...",
specHash: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
});Notes
connect()is Express only. The old Express x402-compat envelope has been removed.requestX402()is the real standards-native x402 rail and automatically handles the payment retry path.- GhostRank credit for x402 depends on merchant-side
reportX402Settlement(...). - Use signer private keys only in trusted backend/server/CLI environments.
