Skip to content

Instantly share code, notes, and snippets.

@AmanRaj1608
Created September 18, 2022 22:06
Show Gist options
  • Save AmanRaj1608/367ba7d242bb801cd734837f06e7be5a to your computer and use it in GitHub Desktop.
Save AmanRaj1608/367ba7d242bb801cd734837f06e7be5a to your computer and use it in GitHub Desktop.
biconomy sdk backend
import Web3 from "web3";
import HDWalletProvider from "@truffle/hdwallet-provider";
import { Biconomy } from "@biconomy/mexa";
const infura = "https://goerli.infura.io/v3/f0493a02561f4419be93dde46cc584c6";
const pkey = "";
const main = async () => {
console.log("start");
let provider = new HDWalletProvider(pkey, infura);
var web3 = new Web3(provider);
let account = (await web3.eth.getAccounts())[0];
console.log("account", account);
const biconomy = new Biconomy(provider, {
apiKey: "PxLkcX2mx.b90c27cc-3659-4c3d-9246-20a206e5bc13",
debug: true,
contractAddresses: ["0x6025735facb2e77eabb5f3bc9d80b7587e2df9f9"],
});
await biconomy.init();
// console.log("biconomy object", biconomy.interfaceMap);
};
main();
@AmanRaj1608
Copy link
Author

Creating new private key on the fly then using it with HDwallet to pass provider to biconomy

const ethers = require("ethers");
const HDWalletProvider = require("@truffle/hdwallet-provider");
const Biconomy = require("@biconomy/mexa").Biconomy;

const main = async () => {
  // create a new private key using ethers
  const pkey = ethers.Wallet.createRandom().mnemonic.phrase;
  // create a new HDWalletProvider using the private key
  // to get eip-1193 compatible provider
  let provider = new HDWalletProvider(pkey, "https://rpc-mumbai.maticvigil.com");
  // create a new Biconomy instance
  const biconomy = new Biconomy(provider, {
    apiKey: "PxLkcX2mx.b90c27cc-3659-4c3d-9246-20a206e5bc13",
    debug: true,
    contractAddresses: ["0x6025735facb2e77eabb5f3bc9d80b7587e2df9f9"],
  });
  await biconomy.init();
};

main();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment