Skip to content

Commit abda828

Browse files
Merge pull request #59 from IntersectMBO/feat/add-transaction-decoder-tool
Add transaction decoder tool
2 parents 928983d + 09aece0 commit abda828

File tree

9 files changed

+156
-16
lines changed

9 files changed

+156
-16
lines changed

docs/app/tools/tx-decoder/page.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { TransactionDecoder } from "./transaction-decoder"
2+
import type { Metadata } from 'next'
3+
4+
export const metadata: Metadata = {
5+
title: 'Transaction Decoder | Evolution SDK',
6+
description: 'Decode Cardano transactions from CBOR hex format',
7+
}
8+
9+
export default function TransactionDecoderPage() {
10+
return (
11+
<div className="container mx-auto px-4 py-8 max-w-6xl">
12+
<div className="mb-8">
13+
<h1 className="text-4xl font-bold mb-4">Transaction Decoder</h1>
14+
<p className="text-muted-foreground text-lg">
15+
Decode Cardano transactions from CBOR hex format. Paste your transaction hex below to inspect its contents.
16+
</p>
17+
</div>
18+
<TransactionDecoder />
19+
</div>
20+
)
21+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use client'
2+
3+
import { useState } from 'react'
4+
import { Core } from "@evolution-sdk/evolution"
5+
6+
export function TransactionDecoder() {
7+
const [txHex, setTxHex] = useState("")
8+
const [decodedJson, setDecodedJson] = useState<string>("")
9+
const [error, setError] = useState<string | null>(null)
10+
11+
const decodeTx = async () => {
12+
setError(null)
13+
setDecodedJson("")
14+
15+
try {
16+
const cleanHex = txHex.trim().replace(/\s+/g, '')
17+
18+
if (!cleanHex) {
19+
setError("Please enter a transaction CBOR hex string")
20+
return
21+
}
22+
23+
const tx = Core.Transaction.fromCBORHex(cleanHex)
24+
const json = JSON.stringify(tx.toJSON(), (key, value) =>
25+
typeof value === 'bigint' ? value.toString() : value
26+
, 2)
27+
setDecodedJson(json)
28+
} catch (err) {
29+
console.error('Decode error:', err)
30+
setError(err instanceof Error ? err.message : "Failed to decode transaction")
31+
}
32+
}
33+
34+
return (
35+
<div className="space-y-6">
36+
<div className="space-y-4">
37+
<button
38+
onClick={decodeTx}
39+
className="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-colors"
40+
>
41+
Decode Transaction
42+
</button>
43+
44+
<div className="space-y-2">
45+
<label htmlFor="tx-hex" className="block text-sm font-medium">
46+
Transaction CBOR Hex
47+
</label>
48+
<textarea
49+
id="tx-hex"
50+
value={txHex}
51+
onChange={(e) => setTxHex(e.target.value)}
52+
placeholder="Paste transaction CBOR hex here..."
53+
className="w-full h-32 px-3 py-2 bg-background border border-border rounded-md font-mono text-sm resize-y focus:outline-none focus:ring-2 focus:ring-ring"
54+
/>
55+
</div>
56+
</div>
57+
58+
{error && (
59+
<div className="p-4 bg-destructive/10 border border-destructive/20 rounded-md">
60+
<p className="text-destructive font-medium">Error decoding transaction:</p>
61+
<p className="text-destructive/80 text-sm mt-1">{error}</p>
62+
</div>
63+
)}
64+
65+
{decodedJson && (
66+
<div className="space-y-2">
67+
<label className="block text-sm font-medium">Decoded Transaction (JSON)</label>
68+
<pre className="w-full p-4 bg-muted border border-border rounded-md overflow-auto max-h-[600px] text-sm">
69+
<code>{decodedJson}</code>
70+
</pre>
71+
</div>
72+
)}
73+
</div>
74+
)
75+
}

docs/content/docs/index.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import { Card, Cards } from 'fumadocs-ui/components/card'
2222
description="Understand the philosophy and design principles behind Evolution SDK"
2323
href="/docs/introduction/why-evolution"
2424
/>
25+
<Card
26+
title="Transaction Decoder"
27+
description="Decode CBOR transaction hex into readable JSON format"
28+
href="/tools/tx-decoder"
29+
/>
2530
<Card
2631
title="Examples"
2732
description="Explore real-world examples and common patterns"

docs/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./out/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

docs/next.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ const config = {
1717
unoptimized: true,
1818
},
1919
serverExternalPackages: ['typescript', 'twoslash'],
20+
turbopack: {
21+
// Redirect imports to use built dist/ instead of src/ TypeScript files
22+
resolveAlias: {
23+
'@evolution-sdk/evolution': '../packages/evolution/dist/index.js',
24+
},
25+
},
2026
}
2127

2228
export default withMDX(config)

docs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
"next-themes": "^0.4.6",
2323
"react": "^19.2.0",
2424
"react-dom": "^19.2.0",
25-
"twoslash": "^0.3.4"
25+
"twoslash": "^0.3.4",
26+
"@evolution-sdk/evolution": "workspace:*"
2627
},
2728
"devDependencies": {
28-
"@evolution-sdk/evolution": "workspace:*",
2929
"@shikijs/twoslash": "^3.14.0",
3030
"@tailwindcss/postcss": "^4.1.12",
3131
"@types/mdx": "^2.0.13",

docs/tsconfig.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626
"@/*": [
2727
"./*"
2828
],
29-
"@evolution-sdk/evolution": [
30-
"../packages/evolution/src/index.ts"
31-
],
32-
"@evolution-sdk/evolution/*": [
33-
"../packages/evolution/src/*"
34-
]
3529
},
3630
"plugins": [
3731
{
@@ -51,4 +45,4 @@
5145
"exclude": [
5246
"node_modules"
5347
]
54-
}
48+
}

packages/evolution/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ export * as Address from "./sdk/Address.js"
33
export * as AddressDetails from "./sdk/AddressDetails.js"
44
export * from "./sdk/client/Client.js"
55
export { createClient } from "./sdk/client/ClientImpl.js"
6-
export * as Devnet from "./sdk/Devnet/Devnet.js"
7-
export * as DevnetDefault from "./sdk/Devnet/DevnetDefault.js"
86
export { runEffect } from "./utils/effect-runtime.js"
97
export * as FeeValidation from "./utils/FeeValidation.js"
108
export { Effect, Either, pipe, Schema } from "effect"

pnpm-lock.yaml

Lines changed: 45 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)