npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

megafuel-js-sdk

v1.0.5

Published

SDK for megafuel product

Downloads

329

Readme

megafuel-js-sdk

This JavaScript SDK is thin wrapper of MegaFuel clients, offering a streamlined interface to interact with the MegaFuel. For more information, please refer to the API documentation.

Network Endpoint

| Network | Paymaster | Sponsor | |:-------------:|:-------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------:| | BSC mainnet | https://bsc-megafuel.nodereal.io | https://open-platform.nodereal.io/{YOUR_API_KEY}/megafuel | | BSC testnet | https://bsc-megafuel-testnet.nodereal.io | https://open-platform.nodereal.io/{YOUR_API_KEY}/megafuel-testnet | | opBNB mainnet | https://opbnb-megafuel.nodereal.io | https://open-platform.nodereal.io/{YOUR_API_KEY}/megafuel | | opBNB testnet | https://opbnb-megafuel-testnet.nodereal.io | https://open-platform.nodereal.io/{YOUR_API_KEY}/megafuel-testnet |

Quick Start

  1. Install dependency
 $ npm install megafuel-js-sdk
  1. Example
import 'dotenv/config';
import {ethers} from "ethers";
import { PaymasterClient } from 'megafuel-js-sdk';

const PAYMASTER_URL="https://bsc-megafuel-testnet.nodereal.io"
const CHAIN_URL="https://data-seed-prebsc-2-s1.binance.org:8545/"
const SPONSOR_URL="https://open-platform.nodereal.io/<api-key>/megafuel-testnet"
const CHAIN_ID="97"

const POLICY_UUID="a2381160-xxxx-xxxx-xxxxceca86556834"
const TOKEN_CONTRACT_ADDRESS="0xeD2.....12Ee"
const RECIPIENT_ADDRESS="0x8e9......3EA2"
const YOUR_PRIVATE_KEY="69......929"

const client = new SponsorClient(SPONSOR_URL, null, { staticNetwork: ethers.Network.from(Number(CHAIN_ID)) });

try {
  // sponsor the tx that interact with the stable coin ERC20 contract
  const res1 = await client.addToWhitelist({
    PolicyUUID: POLICY_UUID,
    WhitelistType: WhitelistType.ToAccountWhitelist,
    Values: [RECIPIENT_ADDRESS]
  });
  console.log("Added ERC20 contract address to whitelist ", res1);
} catch (error){
  console.error("Error:", error)
}

// Provider for assembling the transaction (e.g., mainnet)
const assemblyProvider = new ethers.JsonRpcProvider(CHAIN_URL);

// Provider for sending the transaction (e.g., could be a different network or provider)
const paymasterProvider = new PaymasterClient(PAYMASTER_URL);

const wallet = new ethers.Wallet(YOUR_PRIVATE_KEY, assemblyProvider);
// ERC20 token ABI (only including the transfer function)
const tokenAbi = [
  "function transfer(address,uint256) returns (bool)"
];

// Create contract instance
const tokenContract = new ethers.Contract(TOKEN_CONTRACT_ADDRESS, tokenAbi, wallet);

// Transaction details
const tokenAmount = ethers.parseUnits('1.0', 18); // Amount of tokens to send (adjust decimals as needed)

try {
  // Get the current nonce for the sender's address
  const nonce = await assemblyProvider.getTransactionCount(wallet.address);

  // Create the transaction object
  const transaction = await tokenContract.transfer.populateTransaction(RECIPIENT_ADDRESS, tokenAmount);

  // Add nonce and gas settings
  transaction.from = wallet.address;
  transaction.nonce = nonce;
  transaction.gasLimit = 100000; // Adjust gas limit as needed for token transfers
  transaction.chainId = 97;
  transaction.gasPrice = 0; // Set gas price to 0

  try {
    const sponsorableInfo = await paymasterProvider.isSponsorable(transaction);
    console.log('Sponsorable Information:', sponsorableInfo);
  } catch (error) {
    console.error('Error checking sponsorable status:', error);
  }

  // Sign the transaction
  const signedTx = await wallet.signTransaction(transaction);

  // Send the raw transaction using the sending provider
  const tx = await paymasterProvider.sendRawTransaction(signedTx);
  console.log('Transaction sent:', tx);

} catch (error) {
  console.error('Error sending transaction:', error);
}

More examples can be found in the examples.