Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DeadEnd] Test Biconomy #5

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
NEAR_ACCOUNT_ID=
NEAR_ACCOUNT_PRIVATE_KEY=
NEAR_MULTICHAIN_CONTRACT=multichain-testnet-2.testnet
NEAR_MULTICHAIN_CONTRACT=multichain-testnet-2.testnet

PAYMASTER_KEY=
PAYMASTER_URL=
BUNDLER_URL=
RELAYER_PK=
52 changes: 52 additions & 0 deletions examples/gasless-tx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import dotenv from "dotenv";
import { ethers } from "ethers";
import { createSmartAccountClient } from "@biconomy/account";
import { PaymasterMode } from "@biconomy/paymaster";

const run = async (): Promise<void> => {
dotenv.config();
const config = {
// chain: "sepolia",
// chainId: 11155111,
rpcUrl: "https://rpc.sepolia.ethpandaops.io",
privateKey: process.env.RELAYER_PK!,
biconomyPaymasterApiKey: process.env.PAYMASTER_KEY!,
bundlerUrl: process.env.BUNDLER_URL!,
};

// Generate EOA from private key using ethers.js
const provider = new ethers.providers.JsonRpcProvider(config.rpcUrl);
const relayer = new ethers.Wallet(config.privateKey, provider);

// const biconomyPaymaster = await createPaymaster({
// paymasterUrl: process.env.PAYMASTER_URL!,
// });
console.log("Bundler:", process.env.PAYMASTER_URL);
const smartWallet = await createSmartAccountClient({
signer: relayer,
bundlerUrl: config.bundlerUrl,
biconomyPaymasterApiKey: config.biconomyPaymasterApiKey,
});

const saAddress = await smartWallet.getAccountAddress();
console.log("SA Address", saAddress);

const tx = {
to: "0x1111111111111111111111111111111111111111",
value: 0, // Can't send non-zero values (or tx will fail)
data: "0xdeadbeef",
};

// Send the transaction and get the transaction hash
const userOpResponse = await smartWallet.sendTransaction(tx, {
paymasterServiceData: { mode: PaymasterMode.SPONSORED },
});
const { transactionHash } = await userOpResponse.waitForTxHash();
console.log("Transaction Hash", transactionHash);
const userOpReceipt = await userOpResponse.wait();
if (userOpReceipt.success == "true") {
console.log("UserOp receipt", userOpReceipt);
console.log("Transaction receipt", userOpReceipt.receipt);
}
};
run();
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"typescript": "^5.4.2"
},
"dependencies": {
"@biconomy/account": "^4.1.1",
"@biconomy/paymaster": "^4.1.1",
"@ethereumjs/common": "^4.2.0",
"@ethereumjs/tx": "^5.2.1",
"@ethereumjs/util": "^9.0.2",
Expand Down
Loading