-
Notifications
You must be signed in to change notification settings - Fork 1
Update #1
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
base: main
Are you sure you want to change the base?
Update #1
Changes from all commits
b0f22ca
739af71
3e799aa
0b2f616
e443afa
7c92651
e1865db
c464217
6f043a8
cbd52eb
eaf2d88
f151695
34920a3
0ae3a28
8c0edf8
f73b056
4146953
71de65b
0300b48
f7562a0
17d92c4
0b5f768
daa8ad6
0d91907
0746b69
fd93fbb
17e5e65
7929118
ae24f9c
b920446
526be24
814424d
8562540
11b91da
18670f1
d595c7c
12dd187
86be4ab
089d8d3
a1a6699
1a35228
0e7d480
10ef20e
3a012b9
2679d84
a178f61
51cd9e4
29a34ea
8ff939c
65992ae
f0aca75
11cd5bb
f167a47
741d9a4
8e640ba
a4501b7
e6b6b72
0b45b01
f2673b5
9c99588
b7450ae
3ec4979
068c565
8f14750
29d4b98
24b115d
c2c3caf
1c76ee3
0630dc6
719abff
68af8e8
49e13e8
d07ac17
a06c6cb
d4a006b
b1393b4
1c27b28
6eacbba
4a36249
b20b159
11bbb76
6287578
37ddb89
8dd6f95
e18f8ba
0b87a55
0faeb2c
58e66eb
b65389f
5cba610
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!/usr/bin/env node | ||
| import { JsonRpcProvider, Contract } from 'ethers'; | ||
|
|
||
| async function main() { | ||
| const rpc = process.env.VITE_BASE_RPC || process.env.BASE_RPC || 'https://mainnet.base.org'; | ||
| const postsAddr = process.env.VITE_BASELINE_POSTS || process.env.BASELINE_POSTS; | ||
|
|
||
| console.log('Using RPC:', rpc); | ||
| console.log('Posts contract address:', postsAddr); | ||
|
|
||
| if (!postsAddr) { | ||
| console.error('No Posts contract address provided in env VITE_BASELINE_POSTS'); | ||
| process.exit(2); | ||
| } | ||
|
|
||
| const provider = new JsonRpcProvider(rpc); | ||
|
|
||
| const POSTS_ABI = [ | ||
| 'function getAllPosts() view returns (uint256[])', | ||
| 'function getPost(uint256) view returns (uint256 id, address author, string content, uint256 timestamp, uint256 likesCount, uint256 commentsCount, bool exists)' | ||
| ]; | ||
|
|
||
| try { | ||
| const contract = new Contract(postsAddr, POSTS_ABI, provider); | ||
| console.log('Calling getAllPosts...'); | ||
| const ids = await contract.getAllPosts(); | ||
| console.log('Received ids length:', ids.length); | ||
| if (ids.length > 0) { | ||
| const first = ids[0]; | ||
| console.log('Fetching first post id:', first.toString()); | ||
| const post = await contract.getPost(first); | ||
| console.log('Post:', { | ||
| id: post.id.toString(), | ||
| author: post.author, | ||
| content: (post.content || '').slice(0, 120), | ||
| timestamp: post.timestamp.toString(), | ||
| likes: (post.likesCount?.toString?.() || post[4]?.toString?.()) | ||
| }); | ||
| } else { | ||
| console.log('No posts found on-chain (getAllPosts returned empty array).'); | ||
| } | ||
|
Comment on lines
+23
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Replace getAllPosts call with event scan to enumerate post ids. Since the ABI doesn’t include getAllPosts, query PostCreated logs to grab recent post IDs and then read a post via getPost. - const contract = new Contract(postsAddr, POSTS_ABI, provider);
- console.log('Calling getAllPosts...');
- const ids = await contract.getAllPosts();
- console.log('Received ids length:', ids.length);
- if (ids.length > 0) {
- const first = ids[0];
- console.log('Fetching first post id:', first.toString());
- const post = await contract.getPost(first);
- console.log('Post:', {
- id: post.id.toString(),
- author: post.author,
- content: (post.content || '').slice(0, 120),
- timestamp: post.timestamp.toString(),
- likes: (post.likesCount?.toString?.() || post[4]?.toString?.())
- });
- } else {
- console.log('No posts found on-chain (getAllPosts returned empty array).');
- }
+ const contract = new Contract(postsAddr, POSTS_ABI, provider);
+ console.log('Scanning PostCreated logs...');
+ const topic0 = (await import('ethers')).id('PostCreated(uint256,address,string,uint256)');
+ const logs = await provider.getLogs({ address: postsAddr, topics: [topic0], fromBlock: 0, toBlock: 'latest' });
+ console.log('Found PostCreated logs:', logs.length);
+ if (logs.length > 0) {
+ const last = logs[logs.length - 1];
+ const idHex = last.topics[1]; // indexed id
+ const postId = BigInt(idHex);
+ console.log('Fetching latest post id:', postId.toString());
+ const [post, likeCount] = await contract.getPost(postId);
+ console.log('Post:', {
+ id: post.id.toString(),
+ author: post.author,
+ content: (post.content || '').slice(0, 120),
+ timestamp: post.timestamp.toString(),
+ likes: likeCount?.toString?.()
+ });
+ } else {
+ console.log('No posts found on-chain (no PostCreated logs).');
+ }
🤖 Prompt for AI Agents |
||
| } catch (err) { | ||
| console.error('On-chain checks failed:', (err && err.message) || err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Card } from "@/components/ui/card"; | ||
| import { Button } from "@/components/ui/button"; | ||
|
|
||
| import { useConnect, useAccount } from "wagmi"; | ||
| import { Wallet, Shield, Zap, ChevronRight } from "lucide-react"; | ||
| import { useEffect } from "react"; | ||
| import { base } from 'wagmi/chains'; | ||
| import React, { useEffect } from "react"; | ||
| import heroImage from "@/assets/baseline-hero.jpg"; | ||
|
|
||
| interface ConnectWalletProps { | ||
|
|
@@ -12,13 +14,55 @@ interface ConnectWalletProps { | |
| const ConnectWallet = ({ onConnect }: ConnectWalletProps) => { | ||
| const { connectors, connect } = useConnect(); | ||
| const { isConnected } = useAccount(); | ||
| const baseRpc = (import.meta.env.VITE_BASE_RPC as string | undefined) ?? 'https://mainnet.base.org'; | ||
|
Comment on lines
15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Await connection properly; use
- const { connectors, connect } = useConnect();
+ const { connectors, connectAsync } = useConnect();- try {
- connect({ connector: target });
- } catch (err) {
+ try {
+ await connectAsync({ connector: target });
+ } catch (err) {
console.error('Connect failed', err);
try { (await import('sonner')).toast.error('Failed to connect wallet'); } catch { console.warn('No sonner available'); }
}Also applies to: 110-132 🤖 Prompt for AI Agents |
||
|
|
||
| useEffect(() => { | ||
| if (isConnected) { | ||
| onConnect(); | ||
| } | ||
| }, [isConnected, onConnect]); | ||
|
|
||
| useEffect(() => { | ||
| if (!isConnected) return; | ||
|
|
||
| const ensureBase = async () => { | ||
| try { | ||
| const ethereum = (window as any).ethereum; | ||
| if (!ethereum?.request) { | ||
| try { (await import('sonner')).toast.error('No Ethereum provider available to switch networks'); } catch { /* ignore */ } | ||
| return; | ||
| } | ||
|
|
||
| const currentChainHex = await ethereum.request({ method: 'eth_chainId' }) as string; | ||
| const currentChainId = parseInt(currentChainHex, 16); | ||
| if (currentChainId === base.id) return; | ||
|
|
||
| await ethereum.request({ | ||
| method: 'wallet_addEthereumChain', | ||
| params: [{ | ||
| chainId: '0x' + base.id.toString(16), | ||
| chainName: 'Base Mainnet', | ||
| rpcUrls: [baseRpc], | ||
| nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, | ||
| blockExplorerUrls: ['https://base.blockscout.com/'], | ||
| }], | ||
| }); | ||
|
|
||
| await ethereum.request({ | ||
| method: 'wallet_switchEthereumChain', | ||
| params: [{ chainId: '0x' + base.id.toString(16) }], | ||
| }); | ||
|
|
||
| try { (await import('sonner')).toast.success('Switched to Base Mainnet'); } catch { /* ignore */ } | ||
| } catch (err) { | ||
| console.error('Network switch failed', err); | ||
| try { (await import('sonner')).toast.error('Please switch your wallet to Base Mainnet'); } catch { /* ignore */ } | ||
| } | ||
| }; | ||
|
|
||
| ensureBase(); | ||
| }, [isConnected, baseRpc]); | ||
|
|
||
| const wallets = []; | ||
|
|
||
| return ( | ||
|
|
@@ -34,7 +78,7 @@ const ConnectWallet = ({ onConnect }: ConnectWalletProps) => { | |
| {/* Header */} | ||
| <div className="text-center mb-8"> | ||
| <div className="inline-flex items-center justify-center w-16 h-16 bg-gradient-primary rounded-2xl mb-4 shadow-medium"> | ||
| <span className="text-2xl">⚡</span> | ||
| <span className="text-3xl font-bold text-primary-foreground">B</span> | ||
| </div> | ||
| <h1 className="text-4xl font-bold mb-2"> | ||
| Welcome to <span className="gradient-text">BaseLine</span> | ||
|
|
@@ -61,26 +105,40 @@ const ConnectWallet = ({ onConnect }: ConnectWalletProps) => { | |
|
|
||
| <Card className="p-6 card-glow glass-effect"> | ||
| <h3 className="text-xl font-semibold mb-4 text-center">Connect Your Wallet</h3> | ||
|
|
||
| <div className="space-y-3"> | ||
| {connectors.map((connector) => ( | ||
| <Button | ||
| key={connector.uid} | ||
| variant="default" | ||
| size="lg" | ||
| className="w-full justify-between group btn-gradient" | ||
| onClick={() => connect({ connector })} | ||
| disabled={!connector.ready} | ||
| > | ||
| <div className="flex items-center gap-3"> | ||
| <Wallet className="w-5 h-5" /> | ||
| <div className="text-left"> | ||
| <div className="font-semibold">{connector.name}</div> | ||
| <div className="text-sm opacity-80">Connect with {connector.name}</div> | ||
| </div> | ||
| <Button | ||
| variant="default" | ||
| size="lg" | ||
| className="w-full justify-center group btn-gradient" | ||
| onClick={async () => { | ||
| // Preferred wallet order | ||
| const preferred = ["MetaMask", "Coinbase Wallet"]; | ||
| const findPreferred = connectors.find((c) => preferred.some((p) => c.name.toLowerCase().includes(p.toLowerCase()))); | ||
| const fallback = connectors.find((c) => c.ready) || connectors[0]; | ||
| const target = findPreferred || fallback; | ||
| if (!target) { | ||
| // show fallback message | ||
| try { (await import('sonner')).toast.error('No wallet connectors available'); } catch { console.warn('No sonner available'); } | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| connect({ connector: target }); | ||
| } catch (err) { | ||
| console.error('Connect failed', err); | ||
| try { (await import('sonner')).toast.error('Failed to connect wallet'); } catch { console.warn('No sonner available'); } | ||
| } | ||
| }} | ||
| > | ||
| <div className="flex items-center gap-3"> | ||
| <Wallet className="w-5 h-5" /> | ||
| <div className="text-left"> | ||
| <div className="font-semibold">Connect Wallet</div> | ||
| <div className="text-sm opacity-80">MetaMask · Coinbase Wallet · OKX</div> | ||
| </div> | ||
| <ChevronRight className="w-5 h-5 group-hover:translate-x-1 transition-transform" /> | ||
| </Button> | ||
| ))} | ||
| </div> | ||
| </Button> | ||
| </div> | ||
|
|
||
| <div className="mt-6 text-center"> | ||
|
|
@@ -90,17 +148,10 @@ const ConnectWallet = ({ onConnect }: ConnectWalletProps) => { | |
| </div> | ||
| </Card> | ||
|
|
||
| {/* Network Info */} | ||
| <div className="mt-6 text-center"> | ||
| <div className="inline-flex items-center gap-2 px-3 py-1 bg-accent/50 rounded-full text-sm glass-effect"> | ||
| <div className="connection-dot"></div> | ||
| <span>Base Mainnet (Chain ID: 8453)</span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default ConnectWallet; | ||
| export default ConnectWallet; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ABI mismatch with deployed contract schema (getPost shape) and missing getAllPosts definition.
Your local ABI expects getPost to return 7 fields (incl. likes/comments/existence), but src/lib/contracts.ts defines getPost as
(Post tuple, uint256)and does not expose commentsCount/exists. Also, POSTS_ABI there does not include getAllPosts, yet the script calls it. This will revert at runtime. Align the ABI and stop calling non-existent functions.Apply this minimal ABI fix (align to tuple + likeCount) and switch to events-based discovery (PostCreated) rather than getAllPosts:
📝 Committable suggestion
🤖 Prompt for AI Agents