npm package: @kanalabs/paymaster-sdk
Description: Kanalab's Paymaster SDK
Author: 0xAnto
Latest version: 0.2.0

# @kanalabs/paymaster-sdk

### Install the paymaster SDK

```
npm i @kanalabs/paymaster-sdk
```

### Initialize SDK with Private Key and projectKey

```
import { PaymasterSdk } from "@kanalabs/paymaster-sdk";
const sdk = new PaymasterSdk(
  {
    privateKey:
      "user private key", // Optional
  },
  { projectKey: "your project key",
    network: Network.MAINNET // Default is MAINNET
    chain: chainName.Aptos // Default is Aptos
  }
);
```

### Check If user already whitelisted,

```
const isWhitelisted = await sdk.isWhitelisted();
or
const isWhitelisted = await sdk.isWhitelisted({address: "user address"});

// Response format
{
    success: boolean;
    message: string;
}
```

It will return { success: true, message: 'whitelisted' } if already whitelisted.
It will return { success: true, message: 'not whitelisted' } if it is not whitelisted.

### To add user to whitelist

```
const whitelist = await sdk.addToWhitelist();
or
const whitelist = await sdk.addToWhitelist({address: "user address"});

// Response format
{
    success: boolean;
    message: string;
}
```

It will return { success: true, message: 'Successfully added' } if successfully whitelisted.
It will return { success: true, message: 'already whitelisted' } if user already whitelisted.

### Initialize user account default

```
If that account is not available in Aptos mainnet you can initialize account with the following function.
const initAccount = await sdk.initAccount();
or
const initAccount = await sdk.initAccount({address: "user address"});

// Response format
{
    success: boolean;
    message: string;
}
```

It will return { success: true, message: 'account initialized' } if successfully initialized.

### Initialize user account custom

```
If that account is not available in Aptos mainnet you can initialize and register a custom coin like lzUSDC, whUSDC.
const initAccount = await sdk.initAccount({coin: "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC"});
or
const initAccount = await sdk.initAccount({address: "user address", coin: "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC"});

// Response format
{
    success: boolean;
    message: string;
}
```

It will return { success: true, message: 'account initialized' } if successfully initialized.

### Sponsor Transactions

To make sponsored transactons you can build they required payload and pass it to the sponsoredTxn

```
const payload: TransactionPayload = {
    function: "0x1::aptos_account::transfer_coins",
    functionArguments: [
      "0xa197f0ffe941bf5cfca7af28438c8692464316fd8075baf6145c26051bc85d4d",
      0,
    ],
    typeArguments: ["0x1::aptos_coin::AptosCoin"],
  };
```

```
  const options: TransactionOptions = { gasUnitPrice: 100, maxGasAmount: 2000 };
```

```
try {
    const txn = await sdk.sponsoredTxn({
      data: payload, // Transaction payload
      options: options
    });
    console.log(txn);
    const txnReceipt = await sdk.aptosClient.waitForTransaction({
      transactionHash: txn.hash,
      options: {
        checkSuccess: true,
      },
    });
    console.log("Txn status", txnReceipt.success);
  } catch (error: any) {
    console.log("error", error);
  }
```

### Sponsor Transactions with senderAuth

To make sponsored transactons with senderAuth you have to pass the senderAuth and generated transaction to the sponsoredTxnWithSenderAuth function

```

const txn = await sdk.sponsoredTxnWithSenderAuth({
  transaction: payload, // Generated transaction
  senderAuth: senderAuth, // Sender auth
  options: options,
});
```