Develop your own platform wallets to offer users secure and recoverable options for signing transactions, spending cryptocurrency, and transferring assets.
Import the TweedClient from the @paytweed/core-js SDK, and initialize it using the create() function. Use the from the management console and specify the networks your application will use by passing them to the Tweed provider. Import the Network enum from the SDK.
index.ts
import { Network, TweedClient } from "@paytweed/core-js";
const chains = [Network.ETHEREUM, Network.POLYGON];
const appId = 'YOUR_APP_ID';
let tweed = null;
async function initializeTweedClient(appId, chains) {
if (!client) {
tweed = TweedClient.create(appId, { chains });
}
4. Connect the User
Once the Tweed SDK is set up in your application, the first step is to connect the user. Use the connect function to display the sign-up/in modal. This allows users to create an account, and a wallet is automatically created for them. You can offer multiple sign-up options; for more visit the tweed dashboard.
index.ts
async function connectUser() {
if (tweed) {
const accessToken = await tweed.connect();
}
}
Updating Our Page with the New Code
Add the connect function to index.ts, and create a new function to listen for events from the button we will create in the next step and trigger the connectUser function.
index.ts
import { Network, TweedClient } from "@paytweed/core-js";
const chains = [Network.ETHEREUM, Network.POLYGON];
const appId = 'YOUR_APP_ID';
let tweed = null;
async function initializeTweedClient(appId, chains) {
if (!client) {
tweed = TweedClient.create(appId, { chains });
}
async function connectUser() {
if (tweed) {
const accessToken = await tweed.connect();
}
//this will use by the buton will added in the next step
document.getElementById("connectButton").addEventListener("click", async () => {
try {
await initializeTweedClient(appId, chains);
await connectUser();
} catch (error) {
console.error("Error connecting to Tweed:", error);
}
});
Create index.html page
Add the index.ts file we just created into a <script> with the type module, and create a button.
With the user logged in and authenticated, we can get the Ethereum provider to handle on-chain actions like sending transactions or checking balances.
import { BrowserProvider } from "ethers";
async function getEthProvider() {
const tweedProvider = await tweed.getEthereumProvider(Network.ETHEREUM_SEPOLIA);
const provider = new BrowserProvider(tweedProvider);
}
Updating index.ts with the New Code
Update index.ts to include the getEthProvider function.
index.ts
import { Network, TweedClient } from "@paytweed/core-js";
import { BrowserProvider } from "ethers";
const chains = [Network.ETHEREUM, Network.POLYGON];
const appId = 'YOUR_APP_ID';
let tweed = null;
let provider = null
async function initializeTweedClient(appId, chains) {
if (!client) {
tweed = TweedClient.create(appId, { chains });
}
async function connectUser() {
if (tweed) {
const accessToken = await tweed.connect();
}
async function getEthProvider() {
if (!provider) {
const tweedProvider = await tweed.getEthereumProvider(Network.ETHEREUM_SEPOLIA);
provider = new BrowserProvider(tweedProvider);
}
document.getElementById("connectButton").addEventListener("click", async () => {
try {
await initializeTweedClient(appId, chains);
await connectUser();
} catch (error) {
console.error("Error connecting to Tweed:", error);
}
});
6. Test the Integration
Let's create a transaction using the sendTransaction function from ethers.
async function sendTransaction() {
if (!provider) return;
const signer = await provider.getSigner();
const txHash = await signer.sendTransaction({
to: "0x03928fc2FD91491919F55C8658477fE1352338E7",
value: "0.1",
});
console.log('transaction sent', txHash);
}
Updating index.ts with the New Code
Add the sendTransaction function and create a new function to listen for events from the button we will create in the next step and trigger the sendTransaction function.
index.ts
import { Network, TweedClient } from "@paytweed/core-js";
import { BrowserProvider } from "ethers";
const chains = [Network.ETHEREUM, Network.POLYGON];
const appId = 'YOUR_APP_ID';
let tweed = null;
let provider = null;
async function initializeTweedClient(appId, chains) {
if (!tweed) {
tweed = TweedClient.create(appId, { chains });
}
}
async function connectUser() {
if (tweed) {
const accessToken = await tweed.connect();
}
}
async function getEthProvider() {
if (!provider) {
const tweedProvider = await tweed.getEthereumProvider(Network.ETHEREUM_SEPOLIA);
provider = new BrowserProvider(tweedProvider);
}
}
async function sendTransaction() {
if (!provider) return;
const signer = await provider.getSigner();
const txHash = await signer.sendTransaction({
to: "0x03928fc2FD91491919F55C8658477fE1352338E7",
value: "0.1",
});
console.log('Transaction sent', txHash);
}
document.getElementById("connectButton").addEventListener("click", async () => {
try {
await initializeTweedClient(appId, chains);
await connectUser();
} catch (error) {
console.error("Error connecting to Tweed:", error);
}
});
document.getElementById("sendTx").addEventListener("click", async () => {
try {
await getEthProvider();
await sendTransaction();
} catch (error) {
console.error("Error sending transaction:", error);
}
});
Go to the and . This will generate a unique application ID for your application, which you will need to provide to the Tweed SDK. From the console, you can manage the application and modify its settings.
install to your React app.
Specify the networks your application will use by passing them to the . Import the Network enum from the React SDK.
Once the Tweed SDK is set up in your application, the first step is to connect the user. Use the function from the hook to display the sign-up/in modal. This allows users to create an account, and a wallet is automatically created for them. You can offer multiple sign-up options; for more details, visit here.
Token Checkout
If you are integrating WaaS for token checkout, you are done at this point and can return to continue the
With the user logged in and authenticated, we are able to get the to handle on-chain actions like sending transactions or checking balances.
import hook from tweed SDK
Create a state to hold the and a function to obtain it. In this example, we use the useEffect hook to initialize the provider as soon as the user connects, making it available immediately.
Go to the and . This will generate a unique application ID for your application, which you will need to provide to the Tweed SDK. From the console, you can manage the application and modify its settings.