Skip to content

Commit

Permalink
update blobtx
Browse files Browse the repository at this point in the history
  • Loading branch information
XueMoMo committed Jul 12, 2024
1 parent 414ac22 commit dd9f492
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 74 deletions.
26 changes: 13 additions & 13 deletions app/blobtx/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const BlobTX = () => {
const [isShow, setIsShow] = useState<boolean>(true)
const { disconnect } = useDisconnect()
const [shownettip, setShowNetTip] = useState(false)
const { data: _wc } = useWalletClient({ chainId: ethda.id })
const { sendTransactionAsync } = useSendTransaction({})
const publicClient = usePublicClient({ chainId: ethda.id })
const [transData, setTransData] = useState<{ text: Uint8Array; img: Uint8Array; imgType: string }>()
Expand All @@ -57,10 +56,10 @@ const BlobTX = () => {
const [tempWc, setTempWc] = useState<WalletClient>()
useEffect(() => {
setTempWc(cachedWallet())
})
}, [])
const tempAccountAddrss = tempWc?.account?.address
const validImageTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif', 'image/svg+xml']
const isConnected = account.address && account.isConnected && account.chainId == ethda.id
const isConnected = account.address && account.isConnected
// console.info('isConnected', isConnected, account.address, account.isConnected, account.chain?.id, ethda.id)
const clearAllState = () => {
setLoading({ loading: false, success: false, error: false, errorMsg: '', uploadImageError: '' })
Expand Down Expand Up @@ -104,7 +103,6 @@ const BlobTX = () => {
})
}


useEffect(() => {
if (!isConnected) {
clearAllState()
Expand Down Expand Up @@ -256,23 +254,21 @@ const BlobTX = () => {
}

const onSendTx = async () => {
if (!_wc || !transData || !publicClient || !account || !account.address) return
if (!transData || !publicClient || !account || !account.address) return
try {
setLoading({ loading: true })
const walletClient = tempWc ?? cachedWallet()
const sender: Address = walletClient.account?.address as any
const balance = await publicClient.getBalance({ address: sender })
if (balance < parseEther('0.0001')) {
const hash = await sendTransactionAsync({ account: account.address, to: sender, value: parseEther('0.001') })
if (balance < parseEther('0.0006')) {
const hash = await sendTransactionAsync({ chainId: ethda.id, account: account.address, to: sender, value: parseEther('0.001') })
await publicClient.waitForTransactionReceipt({ hash, confirmations: 3 })
// return setLoading({ loading: false, error: true, errorMsg: 'Insufficient funds for gas' })
}
const blobs = [transData.text, transData.img]
const { commitments, proofs, versionHashs, encodeBlobs } = await getConvertOfZkg(blobs)
const blobBaseFee = await publicClient.getBlobBaseFee()
const perGas = await publicClient.estimateFeesPerGas({ type: 'eip4844' })

console.info('blobBaseFee', blobBaseFee, (perGas.gasPrice ?? 1n) * BigInt(blobs.length) * 128n * 1024n)
console.info('blobBaseFee', blobBaseFee)
const blobsMeta = createMetaDataForBlobs(sender, [
{
content_type: 'text/plain',
Expand Down Expand Up @@ -306,8 +302,9 @@ const BlobTX = () => {
chain: ethda,
})
console.info('tx:', request.gas, request.gasPrice, request.maxPriorityFeePerGas)

const res = await walletClient.signTransaction(request as any)
// @ts-ignore
const res = await walletClient.account.signTransaction(request)
// const res = await walletClient.signTransaction(request as any)
const hexSig = (res.startsWith('0x') ? res : `0x${res}`) as `0x${string}`
const transaction = parseTransaction(hexSig)
if (!transaction) return
Expand Down Expand Up @@ -451,7 +448,10 @@ const BlobTX = () => {
</div>
{tempWc && (
<div className='text-[#FC7823]'>
<span className='text-black mr-2'>BlobTx Account:</span> {formatEthereumAddress(tempWc.account?.address)}
<span className='text-black mr-2'>BlobTx Account:</span>{' '}
<a target='_blank' href={`${ethda.blockExplorers.default.url}/address/${tempAccountAddrss}`}>
{formatEthereumAddress(tempWc.account?.address)}
</a>
</div>
)}
</div>
Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
// reactStrictMode: false,
output: 'export',
webpack: (config) => {
config.resolve.fallback = { fs: false, net: false, tls: false }
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"slick-carousel": "^1.8.1",
"styled-components": "^6.1.8",
"tailwind-merge": "^2.2.1",
"viem": "~2.14.2",
"wagmi": "~2.10.2"
"viem": "2.14.x",
"wagmi": "2.10.x"
},
"browser": {
"fs": false,
Expand Down
82 changes: 26 additions & 56 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dd9f492

Please sign in to comment.