Skip to content

Commit b8baf28

Browse files
committed
Update all blockchain examples
1 parent 8502911 commit b8baf28

File tree

572 files changed

+22791
-187855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

572 files changed

+22791
-187855
lines changed

app-template.txt

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import "./App.css";
2+
import {
3+
useWeb3AuthConnect, useWeb3AuthDisconnect, useWeb3AuthUser, useWeb3Auth
4+
} from "@web3auth/no-modal/react";
5+
import { WALLET_CONNECTORS, AUTH_CONNECTION } from "@web3auth/no-modal";
6+
// Import appropriate RPC methods for each blockchain
7+
// import { getAccounts, getBalance, signMessage, signAndSendTransaction } from "./blockchainRPC";
8+
9+
function App() {
10+
const { connect, isConnected, connectorName, loading: connectLoading, error: connectError } = useWeb3AuthConnect();
11+
const { disconnect, loading: disconnectLoading, error: disconnectError } = useWeb3AuthDisconnect();
12+
const { userInfo } = useWeb3AuthUser();
13+
const { provider } = useWeb3Auth();
14+
15+
// Define blockchain-specific functions here
16+
// const onGetAccounts = async () => {
17+
// if (!provider) {
18+
// uiConsole("provider not initialized yet");
19+
// return;
20+
// }
21+
// const userAccount = await getAccounts(provider);
22+
// uiConsole("Address", userAccount);
23+
// };
24+
25+
function uiConsole(...args: any[]): void {
26+
const el = document.querySelector("#console>p");
27+
if (el) {
28+
el.innerHTML = JSON.stringify(args || {}, null, 2);
29+
}
30+
}
31+
32+
const loggedInView = (
33+
<div className="grid">
34+
<div className="flex-container">
35+
<div>
36+
<button onClick={() => uiConsole(userInfo)} className="card">
37+
Get User Info
38+
</button>
39+
</div>
40+
{/* Add blockchain-specific buttons here */}
41+
<div>
42+
<button onClick={() => disconnect()} className="card">
43+
Log Out
44+
</button>
45+
{disconnectLoading && <div className="loading">Disconnecting...</div>}
46+
{disconnectError && <div className="error">{disconnectError.message}</div>}
47+
</div>
48+
</div>
49+
</div>
50+
);
51+
52+
const unloggedInView = (
53+
// IMP START - Login
54+
<div className="grid">
55+
<button onClick={() => connect(WALLET_CONNECTORS.AUTH, {
56+
authConnection: AUTH_CONNECTION.GOOGLE,
57+
})} className="card">
58+
Login
59+
</button>
60+
{connectLoading && <div className="loading">Connecting...</div>}
61+
{connectError && <div className="error">{connectError.message}</div>}
62+
</div>
63+
// IMP END - Login
64+
);
65+
66+
return (
67+
<div className="container">
68+
<h1 className="title">
69+
<a target="_blank" href="https://web3auth.io/docs/sdk/pnp/web/no-modal" rel="noreferrer">
70+
Web3Auth{" "}
71+
</a>
72+
& BLOCKCHAIN_NAME Example
73+
</h1>
74+
75+
<div className="grid">{isConnected ? loggedInView : unloggedInView}</div>
76+
<div id="console" style={{ whiteSpace: "pre-line" }}>
77+
<p style={{ whiteSpace: "pre-line" }}></p>
78+
</div>
79+
<footer className="footer">
80+
<a
81+
href="https://github.com/Web3Auth/web3auth-pnp-examples/tree/main/web-no-modal-sdk/blockchain-connection-examples/BLOCKCHAIN_NAME-no-modal-example"
82+
target="_blank"
83+
rel="noopener noreferrer"
84+
>
85+
Source code
86+
</a>
87+
</footer>
88+
</div>
89+
);
90+
}
91+
92+
export default App;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"scripts": {
55
"update-web3auth": "lerna exec --concurrency 1 -- 'ncu -u @web3auth/* && npm install'",
6-
"update-web3auth-alpha": "lerna exec --concurrency 1 -- 'ncu -u @web3auth/* --target @next && npm install --legacy-peer-deps'",
6+
"update-web3auth-alpha": "lerna exec --concurrency 1 -- 'ncu -u @web3auth/* --target @next'",
77
"install-all": "lerna exec --concurrency 1 -- 'npm install'",
88
"lint-all": "lerna exec --concurrency 1 -- 'npm run lint'"
99
},

rpc-template.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { IProvider } from "@web3auth/base";
2+
3+
// Get the private key from the Web3Auth provider
4+
export async function getPrivateKey(provider: IProvider): Promise<string> {
5+
try {
6+
const privateKey = await provider.request({ method: "private_key" });
7+
return privateKey as string;
8+
} catch (error) {
9+
throw new Error("Failed to retrieve private key");
10+
}
11+
}
12+
13+
// Get account address
14+
export async function getAccounts(provider: IProvider): Promise<string> {
15+
try {
16+
// Implement blockchain-specific account retrieval here
17+
return "address";
18+
} catch (error) {
19+
throw new Error("Failed to get account address");
20+
}
21+
}
22+
23+
// Get account balance
24+
export async function getBalance(provider: IProvider): Promise<string> {
25+
try {
26+
// Implement blockchain-specific balance retrieval here
27+
return "balance";
28+
} catch (error) {
29+
throw new Error("Failed to get balance");
30+
}
31+
}
32+
33+
// Sign a message
34+
export async function signMessage(provider: IProvider): Promise<string> {
35+
try {
36+
// Implement blockchain-specific message signing here
37+
return "signed message";
38+
} catch (error) {
39+
throw new Error("Failed to sign message");
40+
}
41+
}
42+
43+
// Send a transaction
44+
export async function signAndSendTransaction(provider: IProvider): Promise<string> {
45+
try {
46+
// Implement blockchain-specific transaction sending here
47+
return "transaction hash";
48+
} catch (error) {
49+
throw new Error("Failed to send transaction");
50+
}
51+
}

0 commit comments

Comments
 (0)