Skip to main content

Overview

The Incentiv SDK (@incentiv/dapp-sdk) provides a seamless way to connect your decentralized application (dApp) to the Incentiv blockchain network. It includes:
  • IncentivResolver: For wallet connection and account management
  • IncentivSigner: For signing transactions and interacting with smart contracts
The SDK supports Account Abstraction (AA) wallets, enabling gasless transactions and improved user experience.

Prerequisites

Before you begin, ensure you have:
  • Node.js (v16 or higher)
  • npm or yarn package manager
  • A modern browser with popups enabled for your application
  • Basic knowledge of:
    • React/JavaScript
    • Ethereum/Web3 concepts
    • Smart contracts

Installation

Step 1: Install the SDK

Install the Incentiv DApp SDK using npm:
Or using yarn:

Step 2: Install Additional Dependencies

The SDK requires buffer for Node.js compatibility in browser environments:

Project Setup

Vite Configuration

If you’re using Vite, configure it to support the SDK: vite.config.js:

Environment Variables

Create a configuration file for your environment settings: src/config.js:

Environment Variables Template

Create a .env file (or use environment variables):

Connecting to Wallet

Step 1: Import Required Modules

Step 2: Connect to Wallet

The IncentivResolver is used to connect to the user’s wallet and get their account address:

Complete Wallet Connection Example


Initializing the Signer

After connecting to the wallet, you need to initialize the IncentivSigner to interact with smart contracts. The signer uses Account Abstraction (AA) for gasless transactions.

Step 1: Create Provider

Step 2: Initialize IncentivSigner

Step 3: Prepare Contract Interface

Complete Signer Initialization Example

Making Payments & Signing Transactions

Depositing Funds (Native Token)

To deposit native tokens (CENT) to a smart contract:

Withdrawing Funds

To withdraw funds from a smart contract:

Calling Contract Functions

For any contract function that requires signing:

Reading Contract State (View Functions)

For read-only operations, you don’t need to sign:

Complete Payment Example


Complete Code Examples

Full Integration Example

Here’s a complete React component demonstrating the full integration:

Configuration

Network Configuration

Update your configuration based on the network: Mainnet:

Contract Addresses

Always use checksummed addresses:

Best Practices

1. Error Handling

Always wrap SDK calls in try-catch blocks:

2. Loading States

Provide user feedback during async operations:

3. Transaction Confirmation

Always wait for transaction confirmation:

4. Balance Updates

Update balances after transactions:

5. Address Validation

Validate addresses before using them:

6. Contract Initialization Check

Always check if contract is initialized before use:

7. Use Refs for Signers

Store signer in a ref to avoid re-initialization:

Troubleshooting

Issue: Portal popup is blocked

Solution:
  • Allow popups for your application.
  • Trigger getAccountAddress() from a user action (such as clicking a button).
  • Try the connection again.

Issue: “No wallet address received”

Solution:
  • Verify the Portal URL is correct.
  • Ensure the popup was not blocked.
  • Ensure the user completed the connection flow in the Portal.
  • If the popup was closed or the user rejected the request, ask them to try again.

Issue: Transaction fails with “insufficient funds”

Solution:
  • Check the user’s wallet balance
  • Ensure enough funds for gas fees
  • Verify the amount being sent is correct

Issue: Contract calls fail

Solution:
  • Verify the contract address is correct
  • Check the ABI matches the contract
  • Ensure the signer is properly initialized
  • Verify the function name and parameters are correct

Issue: “Provider not found”

Solution:
  • Check the RPC URL is correct
  • Verify network connectivity
  • Test the RPC endpoint directly

Issue: Buffer is not defined

Solution:
  • Ensure buffer is installed: npm install buffer
  • Configure Vite as shown in the Project Setup section
  • Add buffer to optimizeDeps

API Reference

IncentivResolver

getAccountAddress(portal: string): Promise<string>

Opens the Incentiv Portal in a popup and returns the user’s wallet address after the connection flow is completed. Parameters: Returns:
  • Promise<string>: The user’s wallet address
Example:

IncentivSigner

Constructor

Parameters:
  • address: User’s wallet address
  • provider: Ethers.js provider instance
  • environment: Portal URL
  • entryPoint: EntryPoint contract address
Example:

Additional Resources

License

This guide is provided as-is for educational purposes. Always refer to the official Incentiv SDK documentation for the most up-to-date information.

Example

Follow this example