Skip to content

Instantly share code, notes, and snippets.

@grsLammy
Created October 5, 2023 11:44
Show Gist options
  • Save grsLammy/8ae77511be83a30191f4cbdb8e424f4b to your computer and use it in GitHub Desktop.
Save grsLammy/8ae77511be83a30191f4cbdb8e424f4b to your computer and use it in GitHub Desktop.
setup plasma client
import {
getRootUser,
getChildUser,
getPrivateKeyGoerli,
getInfuraProjectId,
getPrivateKeyMumbai,
} from "../../config";
import { use } from "@maticnetwork/maticjs";
import HDWalletProvider from "@truffle/hdwallet-provider";
import { PlasmaClient } from "@maticnetwork/maticjs-plasma";
import { Web3ClientPlugin } from "@maticnetwork/maticjs-web3";
use(Web3ClientPlugin);
export async function getPlasmaClient(
network = "testnet", // 'testnet' or 'mainnet'
version = "mumbai" // 'mumbai' or 'v1'
): Promise<PlasmaClient | undefined> {
try {
const plasmaClient: PlasmaClient = new PlasmaClient();
return await plasmaClient.init({
network: network,
version: version,
parent: {
provider: new HDWalletProvider(
[getPrivateKeyGoerli()],
`https://goerli.infura.io/v3/${getInfuraProjectId()}`
),
defaultConfig: {
from: getRootUser(),
},
},
child: {
provider: new HDWalletProvider(
[getPrivateKeyMumbai()],
`https://polygon-mumbai.infura.io/v3/${getInfuraProjectId()}`
),
defaultConfig: {
from: getChildUser(),
},
},
});
} catch (error) {
console.log("error unable to initiate plasmaClient", error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment