Skip to content

Commit 5802635

Browse files
committed
feat(project): enable chainsms on onchainkit
1 parent 1045889 commit 5802635

File tree

13 files changed

+794
-89
lines changed

13 files changed

+794
-89
lines changed

README.md

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,104 @@
1+
# Onchain Messenger
2+
3+
An decentralized messaging application built with [OnchainKit](https://onchainkit.xyz) that allows users to send messages directly through Base blockchain transactions. Built with privacy and decentralization in mind - no central server, no message storage, just pure blockchain communication.
4+
15
<p align="center">
26
<picture>
37
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/coinbase/onchainkit/main/site/docs/public/logo/v0-27.png">
48
<img alt="OnchainKit logo vibes" src="https://raw.githubusercontent.com/coinbase/onchainkit/main/site/docs/public/logo/v0-27.png" width="auto">
59
</picture>
610
</p>
711

8-
# Onchain App Template
12+
## Features
913

10-
An Onchain App Template build with [OnchainKit](https://onchainkit.xyz), and ready to be deployed to Vercel.
14+
- 💬 Send and receive messages directly through blockchain transactions
15+
- 🔒 No central server or database - all messages are stored on-chain
16+
- 🌐 Works on Base network for fast and low-cost messaging
17+
- 👥 Easy-to-use contact management
18+
- ⚡ Real-time message updates
19+
- 🎨 Clean and intuitive UI
20+
- 🔐 Connect with any Web3 wallet
1121

12-
Play with it live on https://onchain-app-template.vercel.app
22+
## How it Works
1323

14-
Have fun! ⛵️
24+
Instead of using a traditional smart contract, this messenger uses transaction data to send messages:
1525

16-
<br />
17-
18-
## Setup
26+
1. Messages are encoded into transaction data
27+
2. Transactions are sent with 0 ETH value
28+
3. Recipients can decode messages from transaction data
29+
4. Messages are permanently stored on the blockchain
1930

20-
To ensure all components work seamlessly, set the following environment variables in your `.env` file using `.env.local.example` as a reference.
31+
This approach has several benefits:
32+
- Lower gas costs (no contract deployment needed)
33+
- Simpler architecture
34+
- True decentralization
35+
- Message permanence
2136

22-
You can find the API key on the [Coinbase Developer Portal's OnchainKit page](https://portal.cdp.coinbase.com/products/onchainkit). If you don't have an account, you will need to create one.
37+
## Setup
2338

24-
You can find your Wallet Connector project ID at [Wallet Connect](https://cloud.walletconnect.com).
39+
To run this project locally, you'll need to set up the following environment variables in your `.env` file:
2540

2641
```sh
2742
# See https://portal.cdp.coinbase.com/products/onchainkit
2843
NEXT_PUBLIC_CDP_API_KEY="GET_FROM_COINBASE_DEVELOPER_PLATFORM"
2944

3045
# See https://cloud.walletconnect.com
3146
NEXT_PUBLIC_WC_PROJECT_ID="GET_FROM_WALLET_CONNECT"
47+
48+
# Base network configuration
49+
NEXT_PUBLIC_NETWORK="base"
3250
```
33-
<br />
3451

35-
## Locally run
52+
## Local Development
3653

3754
```sh
38-
# Install bun in case you don't have it
39-
curl -fsSL https://bun.sh/install | bash
55+
# Install dependencies
56+
bun install
4057

41-
# Install packages
42-
bun i
43-
44-
# Run Next app
58+
# Run the development server
4559
bun run dev
4660
```
47-
<br />
61+
62+
## Technical Architecture
63+
64+
The application is built using:
65+
- Next.js 13+ with App Router
66+
- TypeScript for type safety
67+
- Viem for blockchain interactions
68+
- OnchainKit for Web3 components
69+
- TailwindCSS for styling
70+
- Base network for transactions
71+
72+
Key components:
73+
- `MessageUtils`: Handles message encoding/decoding
74+
- `ConversationList`: Manages contact list and chat history
75+
- `MessageInput`: Handles message sending
76+
- `MessageList`: Displays conversation threads
77+
78+
## Security Considerations
79+
80+
- All messages are public on the blockchain
81+
- Anyone can read the message history
82+
- Addresses are publicly visible
83+
- No encryption (yet) - future versions may include E2E encryption
84+
85+
## Contributing
86+
87+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
4888

4989
## Resources
5090

5191
- [OnchainKit documentation](https://onchainkit.xyz)
52-
- We use the [OnchainKit Early Adopter](https://github.com/neodaoist/onchainkit-early-adopter) contract written by neodaoist [[X]](https://x.com/neodaoist)
53-
54-
<br />
92+
- [Base Network documentation](https://docs.base.org)
93+
- [Viem documentation](https://viem.sh)
5594

5695
## License
5796

5897
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
5998

60-
## Need more help?
99+
## Support
61100

62-
If you have any questions or need help, feel free to reach out to us on [Discord](https://discord.gg/8gW3h6w5)
63-
or open a [Github issue](https://github.com/coinbase/onchainkit/issues) or DMs us
64-
on X at [@onchainkit](https://x.com/onchainkit), [@zizzamia](https://x.com/zizzamia), [@fkpxls](https://x.com/fkpxls).
101+
If you have any questions or need help, you can:
102+
- Open an issue on GitHub
103+
- Follow us on X [@codingsh](https://x.com/codingsh)
104+
- Follow us on Farcaster [@codingsh](https://warp.com/codingsh)

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
2-
"name": "onchain-app-template",
2+
"name": "onchain-app-chainsms",
33
"private": true,
44
"version": "0.0.0",
5+
"author": "codingsh",
56
"scripts": {
67
"build": "next build",
78
"check": "biome check --write .",
@@ -18,6 +19,7 @@
1819
},
1920
"dependencies": {
2021
"@coinbase/onchainkit": "^0.35.6",
22+
"lucide-react": "^0.475.0",
2123
"next": "^14.2.5",
2224
"permissionless": "^0.1.26",
2325
"react": "^18",
@@ -26,24 +28,24 @@
2628
},
2729
"devDependencies": {
2830
"@biomejs/biome": "^1.8.0",
29-
"@types/node": "^20.11.8",
30-
"@types/react": "^18.2.48",
31+
"@testing-library/jest-dom": "^6.4.6",
32+
"@testing-library/react": "^14.2.0",
33+
"@types/node": "22.13.4",
34+
"@types/react": "19.0.9",
3135
"@types/react-dom": "^18.2.7",
3236
"@vitest/coverage-v8": "^3.0.5",
3337
"@vitest/ui": "^3.0.5",
3438
"@wagmi/cli": "latest",
3539
"autoprefixer": "^10.4.19",
3640
"bufferutil": "^4.0.7",
3741
"encoding": "^0.1.13",
38-
"lokijs": "^1.5.12",
3942
"jsdom": "^24.1.0",
43+
"lokijs": "^1.5.12",
4044
"pino-pretty": "^10.2.0",
4145
"postcss": "^8.4.38",
4246
"supports-color": "^9.4.0",
4347
"tailwindcss": "^3.4.0",
44-
"@testing-library/jest-dom": "^6.4.6",
45-
"@testing-library/react": "^14.2.0",
46-
"typescript": "^5.3.3",
48+
"typescript": "5.7.3",
4749
"utf-8-validate": "^6.0.3",
4850
"vitest": "^3.0.5"
4951
}

src/app/layout.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export const viewport = {
1919
};
2020

2121
export const metadata: Metadata = {
22-
title: 'Onchain App Template',
23-
description: 'Built with OnchainKit',
22+
title: 'Onchain Message APP',
23+
description: 'Build by codingsh',
2424
openGraph: {
25-
title: 'Onchain App Template',
26-
description: 'Built with OnchainKit',
25+
title: 'Onchain Message APP',
26+
description: 'Build by codingsh',
2727
images: [`${NEXT_PUBLIC_URL}/vibes/vibes-19.png`],
2828
},
2929
};

src/app/page.tsx

Lines changed: 110 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,129 @@
11
'use client';
2+
3+
import { useState, useEffect } from 'react';
4+
import { useAccount } from 'wagmi';
5+
import { MessageCircle, Menu, X, Send } from 'lucide-react';
26
import Footer from 'src/components/Footer';
3-
import TransactionWrapper from 'src/components/TransactionWrapper';
47
import WalletWrapper from 'src/components/WalletWrapper';
58
import { ONCHAINKIT_LINK } from 'src/links';
69
import OnchainkitSvg from 'src/svg/OnchainkitSvg';
7-
import { useAccount } from 'wagmi';
810
import LoginButton from '../components/LoginButton';
911
import SignupButton from '../components/SignupButton';
12+
import MessageSection from '../components/MessageSection';
1013

1114
export default function Page() {
1215
const { address } = useAccount();
16+
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
17+
const [isLoading, setIsLoading] = useState(true);
18+
19+
20+
useEffect(() => {
21+
const timer = setTimeout(() => setIsLoading(false), 1000);
22+
return () => clearTimeout(timer);
23+
}, []);
1324

1425
return (
15-
<div className="flex h-full w-96 max-w-full flex-col px-1 md:w-[1008px]">
16-
<section className="mt-6 mb-6 flex w-full flex-col md:flex-row">
17-
<div className="flex w-full flex-row items-center justify-between gap-2 md:gap-0">
18-
<a
19-
href={ONCHAINKIT_LINK}
20-
title="onchainkit"
21-
target="_blank"
22-
rel="noreferrer"
23-
>
24-
<OnchainkitSvg />
25-
</a>
26-
<div className="flex items-center gap-3">
27-
<SignupButton />
28-
{!address && <LoginButton />}
26+
<div className="min-h-screen bg-gray-50">
27+
{/* Header */}
28+
<header className="fixed top-0 left-0 right-0 z-50 bg-white border-b border-gray-200">
29+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
30+
<div className="flex justify-between items-center h-16">
31+
{/* Logo */}
32+
<div className="flex items-center">
33+
Message APP
34+
</div>
35+
36+
{/* Desktop Navigation */}
37+
<div className="hidden md:flex items-center gap-4">
38+
<SignupButton />
39+
{!address && <LoginButton />}
40+
</div>
41+
42+
{/* Mobile menu button */}
43+
<div className="md:hidden">
44+
<button
45+
onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}
46+
className="p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100"
47+
>
48+
{isMobileMenuOpen ? <X size={24} /> : <Menu size={24} />}
49+
</button>
50+
</div>
2951
</div>
3052
</div>
31-
</section>
32-
<section className="templateSection flex w-full flex-col items-center justify-center gap-4 rounded-xl bg-gray-100 px-2 py-4 md:grow">
33-
<div className="flex h-[450px] w-[450px] max-w-full items-center justify-center rounded-xl bg-[#030712]">
34-
<div className="rounded-xl bg-[#F3F4F6] px-4 py-[11px]">
35-
<p className="font-normal text-indigo-600 text-xl not-italic tracking-[-1.2px]">
36-
npm install @coinbase/onchainkit
37-
</p>
53+
54+
{/* Mobile Navigation */}
55+
{isMobileMenuOpen && (
56+
<div className="md:hidden border-t border-gray-200 bg-white">
57+
<div className="px-2 pt-2 pb-3 space-y-1">
58+
<SignupButton />
59+
{!address && <LoginButton />}
60+
</div>
61+
</div>
62+
)}
63+
</header>
64+
65+
{/* Main Content */}
66+
<main className="pt-16 min-h-screen">
67+
{isLoading ? (
68+
<div className="flex items-center justify-center min-h-[calc(100vh-4rem)]">
69+
<div className="flex flex-col items-center gap-4">
70+
<div className="animate-spin rounded-full h-12 w-12 border-4 border-indigo-500 border-t-transparent" />
71+
<p className="text-gray-500">Loading Onchain Messenger...</p>
72+
</div>
73+
</div>
74+
) : address ? (
75+
<div className="max-w-7xl mx-auto h-[calc(100vh-4rem)]">
76+
<div className="h-full bg-white shadow-xl rounded-lg overflow-hidden">
77+
<MessageSection address={address} />
78+
</div>
3879
</div>
39-
</div>
40-
{address ? (
41-
<TransactionWrapper address={address} />
4280
) : (
43-
<WalletWrapper
44-
className="w-[450px] max-w-full"
45-
text="Sign in to transact"
46-
/>
81+
<div className="max-w-2xl mx-auto px-4 py-16 sm:px-6 sm:py-24 lg:px-8">
82+
<div className="text-center">
83+
<MessageCircle className="mx-auto h-16 w-16 text-indigo-500" />
84+
<h1 className="mt-4 text-4xl font-bold tracking-tight text-gray-900 sm:text-5xl">
85+
Onchain Messaging
86+
</h1>
87+
<p className="mt-4 text-lg text-gray-500">
88+
Send and receive messages directly through the blockchain.
89+
Secure, decentralized, and always available.
90+
</p>
91+
<div className="mt-10">
92+
<WalletWrapper
93+
className="inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700"
94+
text="Connect Wallet to Start Messaging"
95+
/>
96+
</div>
97+
98+
{/* Features */}
99+
<div className="mt-20 grid grid-cols-1 gap-8 sm:grid-cols-2 lg:grid-cols-3">
100+
<div className="pt-6">
101+
<div className="flow-root rounded-lg bg-gray-50 px-6 pb-8">
102+
<div className="-mt-6">
103+
<div className="inline-flex items-center justify-center rounded-md bg-indigo-500 p-3 shadow-lg">
104+
<Send className="h-6 w-6 text-white" />
105+
</div>
106+
<h3 className="mt-8 text-lg font-medium text-gray-900">Direct Messaging</h3>
107+
<p className="mt-5 text-base text-gray-500">
108+
Send messages directly through blockchain transactions
109+
</p>
110+
</div>
111+
</div>
112+
</div>
113+
114+
{/* Add more feature cards here */}
115+
</div>
116+
</div>
117+
</div>
47118
)}
48-
</section>
49-
<Footer />
119+
</main>
120+
121+
{/* Footer */}
122+
<footer className="bg-white border-t border-gray-200">
123+
<div className="max-w-7xl mx-auto py-4 px-4 sm:px-6 lg:px-8">
124+
<Footer />
125+
</div>
126+
</footer>
50127
</div>
51128
);
52-
}
129+
}

0 commit comments

Comments
 (0)