Skip to content

Commit

Permalink
decoded smart contract data
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason Smith committed Nov 28, 2024
1 parent 99790d7 commit c29adae
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"decimal.js": "^10.4.3",
"ethers": "^6.13.4",
"interchainjs": "0.0.1-beta.34",
"json-bigint": "^1.0.0",
"next": "^13",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
20 changes: 17 additions & 3 deletions pages/ethers/parse-tx.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { Transaction } from "ethers";
import { TextField, Box, Text, Button } from "@interchain-ui/react";
import { useState } from "react";
import { Transaction, Interface } from "ethers";
import { Box, Text, Button } from "@interchain-ui/react";
import { useEffect, useState } from "react";
import abi from './abi.json'
const JSONbig = require('json-bigint')

export default function ParseTx() {
const iface = new Interface(abi)

const [rawTx, setRawTx] = useState("");
const [decodedTx, setDecodedTx] = useState<Transaction | null>(null);
const [dataDecoded, setDataDecoded] = useState<object | null>(null)

useEffect(()=>{
if (!decodedTx) return
setDataDecoded({dataDecoded:iface.parseTransaction({ data: decodedTx.data })})
}, [decodedTx])

return (
<Box display='flex' padding='20px' flexDirection='column' alignItems='center' justifyContent='center' minHeight='100vh'>
Expand All @@ -25,6 +35,10 @@ export default function ParseTx() {
{decodedTx&&<Text attributes={{whiteSpace: 'pre-line', padding: '2rem'}} as="div">
{JSON.stringify(decodedTx, null, 2)}
</Text>}

{dataDecoded&&<Text attributes={{whiteSpace: 'pre-line', padding: '2rem'}} as="div">
{JSONbig.stringify(dataDecoded, null, 2)}
</Text>}
</Box>
)
}
28 changes: 25 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3891,14 +3891,21 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.13.tgz#2af91918ee12d9d32914feb13f5326658461b451"
integrity sha512-hCZTSvwbzWGvhqxp/RqVqwU999pBf2vp7hzIjiYOsl8wqOmUxkQ6ddw1cV3l8811+kdUFus/q4d1Y3E3SyEifA==

"@types/[email protected]", "@types/react-dom@^18.3.0":
"@types/[email protected]":
version "18.0.9"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.9.tgz#ffee5e4bfc2a2f8774b15496474f8e7fe8d0b504"
integrity sha512-qnVvHxASt/H7i+XG1U1xMiY5t+IHcPGUK7TDMDzom08xa7e86eCeKOiLZezwCKVxJn6NEiiy2ekgX8aQssjIKg==
dependencies:
"@types/react" "*"

"@types/react@*", "@types/[email protected]", "@types/react@^18.3.3":
"@types/react-dom@^18.3.0":
version "18.3.1"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.3.1.tgz#1e4654c08a9cdcfb6594c780ac59b55aad42fe07"
integrity sha512-qW1Mfv8taImTthu4KoXgDfLuk4bydU6Q/TkADnDWWHwi4NX4BR+LWfTp2sVmTqRrsHvyDDTelgelxJ+SsejKKQ==
dependencies:
"@types/react" "*"

"@types/react@*", "@types/[email protected]":
version "18.0.25"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.25.tgz#8b1dcd7e56fe7315535a4af25435e0bb55c8ae44"
integrity sha512-xD6c0KDT4m7n9uD4ZHi02lzskaiqcBxf4zi+tXZY98a04wvc0hi/TcCPC2FOESZi51Nd7tlUeOJY8RofL799/g==
Expand All @@ -3907,6 +3914,14 @@
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/react@^18.3.3":
version "18.3.12"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.12.tgz#99419f182ccd69151813b7ee24b792fe08774f60"
integrity sha512-D2wOSq/d6Agt28q7rSI3jhU7G6aiuzljDGZ2hTZHIkrTLUI+AF3WMeKkEZ9nN2fkBAlcktT6vcZjDFiIhMYEQw==
dependencies:
"@types/prop-types" "*"
csstype "^3.0.2"

"@types/scheduler@*":
version "0.23.0"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.23.0.tgz#0a6655b3e2708eaabca00b7372fafd7a792a7b09"
Expand Down Expand Up @@ -4589,7 +4604,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.1.tgz#c4df7dc496bd849d4c9464344c1aa74228b4dac6"
integrity sha512-pHm4LsMJ6lzgNGVfZHjMoO8sdoRhOzOH4MLmY65Jg70bpxCKu5iOHNJyfF6OyvYw7t8Fpf35RuzUyqnQsj8Vig==

bignumber.js@^9.1.2:
bignumber.js@^9.0.0, bignumber.js@^9.1.2:
version "9.1.2"
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.2.tgz#b7c4242259c008903b13707983b5f4bbd31eda0c"
integrity sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==
Expand Down Expand Up @@ -6951,6 +6966,13 @@ jsesc@^3.0.2, jsesc@~3.0.2:
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-3.0.2.tgz#bb8b09a6597ba426425f2e4a07245c3d00b9343e"
integrity sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==

json-bigint@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/json-bigint/-/json-bigint-1.0.0.tgz#ae547823ac0cad8398667f8cd9ef4730f5b01ff1"
integrity sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==
dependencies:
bignumber.js "^9.0.0"

[email protected]:
version "3.0.1"
resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13"
Expand Down

0 comments on commit c29adae

Please sign in to comment.