Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚑 metamask smart tx bug #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.28.4",
"@tanstack/react-query": "^5.51.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"viem": "2.x",
"wagmi": "^2.5.11"
"wagmi": "^2.10.10"
},
"devDependencies": {
"@types/react": "^18.2.64",
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WagmiProvider } from 'wagmi'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'

import { config } from './wagmi.js'
import { config } from './wagmiConfig'
import Wallet from './Wallet'

const queryClient = new QueryClient()
Expand Down
38 changes: 36 additions & 2 deletions src/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChangeEvent, useState } from 'react'
import {
useConfig,
useConnect,
useAccount,
useChainId,
useDisconnect,
useConnections,
Expand All @@ -11,11 +12,12 @@ import {
} from 'wagmi'

import { watchAsset } from 'viem/actions'
import { getConnectorClient } from '@wagmi/core'
import { getConnectorClient, sendTransaction } from '@wagmi/core'

export default function () {
const config = useConfig()
const chainId = useChainId()
const { address } = useAccount()

const { disconnect } = useDisconnect()
const connections = useConnections()
Expand Down Expand Up @@ -77,6 +79,33 @@ export default function () {
})
}

const sendSelfTx = async () => {
try {
console.log({
to: address,
value: BigInt(1),
gas: BigInt(21000),
})
sendTransaction(config, {
to: address,
value: BigInt(1),
gas: BigInt(21000),
})
.then((d) => console.log('tx resp', d))
.catch((err) => console.log('tx error', err))

sendTransaction(config, {
to: address,
value: BigInt(1),
gas: BigInt(21000),
})
.then((d) => console.log('tx resp', d))
.catch((err) => console.log('tx error', err))
} catch (err) {
console.log(err)
}
}

return (
<>
<div>
Expand Down Expand Up @@ -139,11 +168,16 @@ export default function () {
</button>
{writeError && <div>{writeError.message}</div>}
</div>
<div>
<button type='button' onClick={sendSelfTx}>
Send self-tx
</button>
</div>
</div>
<div>
<h2>Disconnect</h2>
<div>
<button type='button' onClick={disconnect}>
<button type='button' onClick={() => disconnect()}>
disconnect
</button>
</div>
Expand Down
18 changes: 0 additions & 18 deletions src/wagmi.ts

This file was deleted.

17 changes: 17 additions & 0 deletions src/wagmiConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { mainnet } from 'wagmi/chains'
import { http, createConfig } from 'wagmi'
import { injected, walletConnect } from 'wagmi/connectors'

export const config = createConfig({
chains: [mainnet],
connectors: [
injected(),
walletConnect({
projectId: '983bf7efbc12ef7eeac5ac1378f164d6',
showQrModal: true,
}),
],
transports: {
[mainnet.id]: http(),
},
})
Loading