Skip to content

Commit 4854c2f

Browse files
committed
Pre Generate TON Address using Torus
1 parent e36b441 commit 4854c2f

File tree

4 files changed

+250
-117
lines changed

4 files changed

+250
-117
lines changed

web-no-modal-sdk/blockchain-connection-examples/ton-no-modal-example/package-lock.json

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web-no-modal-sdk/blockchain-connection-examples/ton-no-modal-example/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"@testing-library/jest-dom": "^5.16.5",
88
"@testing-library/react": "^13.4.0",
99
"@testing-library/user-event": "^14.4.3",
10+
"@toruslabs/fnd-base": "^14.2.0",
11+
"@toruslabs/torus.js": "^15.1.1",
1012
"@types/jest": "^29.2.4",
1113
"@types/node": "^18.11.18",
1214
"@types/react": "^18.0.26",

web-no-modal-sdk/blockchain-connection-examples/ton-no-modal-example/src/App.tsx

+47-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from "react";
2-
import { Web3AuthNoModal as Web3Auth } from "@web3auth/no-modal";
2+
import { Web3AuthNoModal as Web3Auth, Web3AuthNoModal } from "@web3auth/no-modal";
33
import { CHAIN_NAMESPACES, IProvider, UX_MODE, WALLET_ADAPTERS, WEB3AUTH_NETWORK } from "@web3auth/base";
44
import { CommonPrivateKeyProvider } from "@web3auth/base-provider";
55
import { AuthAdapter } from "@web3auth/auth-adapter";
@@ -11,7 +11,7 @@ import TonRPC from "./tonRpc";
1111
const testnetRpc = await getHttpEndpoint({
1212
network: "testnet",
1313
protocol: "json-rpc",
14-
});
14+
});
1515

1616
const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ"; // get from https://dashboard.web3auth.io
1717

@@ -35,17 +35,25 @@ function App() {
3535

3636
const privateKeyProvider = new CommonPrivateKeyProvider({ config: { chainConfig } });
3737

38-
const web3auth = new Web3Auth({
38+
const web3auth = new Web3AuthNoModal({
3939
clientId,
4040
privateKeyProvider,
4141
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
42+
useCoreKitKey: true,
4243
});
4344

4445
setWeb3auth(web3auth);
4546

4647
const authAdapter = new AuthAdapter({
4748
adapterSettings: {
4849
uxMode: UX_MODE.REDIRECT,
50+
loginConfig: {
51+
google: {
52+
verifier: "w3a-google-demo",
53+
typeOfLogin: "google",
54+
clientId: "519228911939-cri01h55lsjbsia1k7ll6qpalrus75ps.apps.googleusercontent.com", //use your app client id you got from google
55+
},
56+
},
4957
},
5058
});
5159
web3auth.configureAdapter(authAdapter);
@@ -113,6 +121,16 @@ function App() {
113121
uiConsole(address);
114122
};
115123

124+
const getPreGenAccounts = async () => {
125+
if (!provider) {
126+
uiConsole("provider not initialized yet");
127+
return;
128+
}
129+
const rpc = new TonRPC(provider);
130+
const address = await rpc.getPreGenAccounts();
131+
uiConsole(address);
132+
};
133+
116134
const getBalance = async () => {
117135
if (!provider) {
118136
uiConsole("provider not initialized yet");
@@ -175,7 +193,12 @@ function App() {
175193
</div>
176194
<div>
177195
<button onClick={getAccounts} className="card">
178-
Get Accounts
196+
Get Account
197+
</button>
198+
</div>
199+
<div>
200+
<button onClick={getPreGenAccounts} className="card">
201+
Get PreGen Account
179202
</button>
180203
</div>
181204
<div>
@@ -208,18 +231,32 @@ function App() {
208231
<p style={{ whiteSpace: "pre-line" }}>Logged in Successfully!</p>
209232
</div>
210233
<div className="faucet-message">
211-
<p>Need test TON? Click <a href="https://faucet.tonxapi.com/" target="_blank" rel="noopener noreferrer">
234+
<p>
235+
Need test TON? Click{" "}
236+
<a href="https://faucet.tonxapi.com/" target="_blank" rel="noopener noreferrer">
212237
here
213-
</a> to visit the faucet and receive free testnet tokens.</p>
238+
</a>{" "}
239+
to visit the faucet and receive free testnet tokens.
240+
</p>
214241
<p>Remember to use your TON testnet address when requesting tokens from the faucet.</p>
215242
</div>
216243
</>
217244
);
218245

219246
const unloggedInView = (
220-
<button onClick={login} className="card">
221-
Login
222-
</button>
247+
<>
248+
<button onClick={login} className="card">
249+
Login
250+
</button>
251+
<div>
252+
<button onClick={getPreGenAccounts} className="card">
253+
Get PreGen Account
254+
</button>
255+
</div>
256+
<div id="console" style={{ whiteSpace: "pre-line" }}>
257+
<p style={{ whiteSpace: "pre-line" }}></p>
258+
</div>
259+
</>
223260
);
224261

225262
return (
@@ -241,4 +278,4 @@ function App() {
241278
);
242279
}
243280

244-
export default App;
281+
export default App;

0 commit comments

Comments
 (0)