0.0.9 • Published 1 year ago

@thangnn91/paymaster-helper-v6 v0.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Paymaster Helper

A paymaster is a smart contract that can pay for transactions for its users, executing any logic to decide whether it should forward a transaction. For example, developers can allow users to run transactions for free or pay in your application's ERC-20 token instead. The library helps developers easily interact with paymaster contracts

🛠 Prerequisites

📥 Installation & Setup

Using npm package manager

npm i @thangnn91/paymaster-helper-v6

Using yarn

yarn add @thangnn91/paymaster-helper-v6

📝 Examples

Types

interface BaseProps {
  network: "testnet" | "mainnet";
  paymasterAddress?: string;
  populateTransaction: ethers.ContractTransaction;
  innerInput?: string;
}

interface WalletExecuteProps extends BaseProps {
  signer: string | Wallet;
  paymentToken?: string;
  nftType?: 0 | 1 | 2 | 3;
}

interface SignerExecuteProps extends BaseProps {
  signer?: Signer;
  paymentToken?: string;
  nftType?: 0 | 1 | 2 | 3;
}

//output data is used to execute outside
export type BuilderOutput = {
  populatedTx: ethers.PopulatedTransaction;
  gasLimit: BigNumber;
  gasPrice: BigNumber;
};

Using by wallet/private key

import { WalletPaymaster, SignerPaymaster } from "@holdstation/paymaster-helper"

const contract = new Contract(CONTRACT_ADDRESS, CONTRACT_ABI, provider)
const populateContract = await contract.populateTransaction[method](...params, {
      from: ACCOUNT,
});

//execute by wallet
await WalletPaymaster.paymasterExecute({
  network: "testnet",
  signer: signer,
  paymentToken: PAYMENT_TOKEN,
  populateTransaction: populateContract
})

//execute using private key
await WalletPaymaster.paymasterExecute({
  network: "testnet",
  signer: PRIVATE_KEY,
  paymentToken: PAYMENT_TOKEN,
  populateTransaction: populateContract
})

Using by Web3Provider Signer (client extension)

function walletClientToSigner(walletClient: WalletClient) {
    const { account, chain, transport } = walletClient;
    const network = {
      chainId: chain.id,
      name: chain.name,
      ensAddress: chain.contracts?.ensRegistry?.address,
    };
    const provider = new Web3Provider(transport, network);
    const signer = provider.getSigner(account.address);
    return signer;
}

const walletConnectSigner = walletClientToSigner(walletClient);

await SignerPaymaster.paymasterExecute({
  //If no signer is specified, we will obtain it from the extension.
  signer: walletConnectSigner,
  network: "testnet",
  paymentToken: PAYMENT_TOKEN,
  populateTransaction: populateContract
})
0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago