diff --git a/app/tools/components/AbiEncoder.tsx b/app/tools/components/AbiEncoder.tsx index 24fd0da..1a9d624 100644 --- a/app/tools/components/AbiEncoder.tsx +++ b/app/tools/components/AbiEncoder.tsx @@ -1,7 +1,7 @@ 'use client' import React, { useState } from 'react' -import { ethers, Contract, JsonRpcProvider} from 'ethers' +import { ethers, Contract, JsonRpcProvider } from 'ethers' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Textarea } from '@/components/ui/textarea' @@ -22,6 +22,7 @@ export default function AbiEncoder() { const [providerUrl, setProviderUrl] = useState('') const [encodedData, setEncodedData] = useState('') const [error, setError] = useState('') + const [isCopied, setIsCopied] = useState(false) const handleEncodeData = async () => { try { @@ -51,13 +52,35 @@ export default function AbiEncoder() { } } - const copyToClipboard = () => { - navigator.clipboard.writeText(encodedData) + const copyToClipboard = (text: string) => { + navigator.clipboard.writeText(text) + setIsCopied(true) + setTimeout(() => setIsCopied(false), 2000) } + const codeSnippet = `const { ethers } = require('ethers'); + +const iface = new ethers.Interface(ABI); +const data = iface.encodeFunctionData("function_name", [arg1, arg2, arg3, ...]);` + + const abiPlaceholder = `[ + { + "inputs": [ + { + "internalType": "uint256", + "name": "num", + "type": "uint256" + } + ], + "name": "store", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ]` + return ( -
-

ABI Encoder

+
{error && (
{error}
)} @@ -65,7 +88,7 @@ export default function AbiEncoder() {