Papaya Finance Protocol
SDKProtocol
  • Introduction
  • Interaction
  • Getting Started
    • Initial Setup
    • Integration Steps
    • Go Live
  • Features
    • Real-Time Payment Streaming
    • Supported Networks
    • Business Dashboard
  • Use Cases
    • For Enterprises
    • For Financial Services
    • For Digital Economy
  • FAQ
  • Glossary
  • Future Development
  • Protocol
    • Common Methods
    • Recurring Payments
    • Subscription Methods
    • Auto Top-up
    • Liquidations
    • Fees
    • Advanced Section
      • Events
      • Subscriptions
      • Projects
      • Signatures
  • SDK
    • Installation
    • Quick Start
    • API
      • PapayaGetter
      • PapayaInteraction
      • PapayaBySigInteraction
Powered by GitBook
On this page
  • constructor
  • claimProjectId
  • setDefaultSettings
  • setSettingsForUser
  • deposit
  • depositFor
  • withdraw
  • withdrawTo
  • pay
  • subscribe
  • unsubscribe
  • liquidate
  1. SDK
  2. API

PapayaInteraction

Class for using writable methods of Papaya Contract

PreviousPapayaGetterNextPapayaBySigInteraction

Last updated 8 months ago


constructor

constructor({papayaAddress: string, provider?: JsonRpcProvider, secretKey?: string}) 

parameters

  • papayaAddress(`0x{string}`) - smart-contract address

  • provider( JsonRpcProvider ) - jsonRpc blockchain provider from

  • secretKey(string) - wallet private key

secretKey and rpcUrl are mostly made for the NodeJS environment. It is not recommended to use them in browser.

usage

import { PapayaInteraction } from "@papaya-metaverse/papaya-sdk"

const papayaInteraction = new PapayaInteraction({
    papayaAddress: "0x1c3E45F2D9Dd65ceb6a644A646337015119952ff",
    provider:  new JsonRpcProvider("https://polygon.infura.io/v3/${INFURA_API_KEY}"),
    //secretKey: "<WALLET_PRIVATE_KEY>" - only when there is no way to allow users to connect their wallets
})

claimProjectId

description

This method assigns a unique number to your wallet, it needed for current functionality of projects

claimProjectId(): Promise<string>

usage

//...

(async () => {
    const transaction = await papayaInteraction.claimProjectId()
})()

setDefaultSettings

description

The default settings are the fee settings that will be set for all users of your project

parameters

setDefaultSettings(initialized = true, projectFee: number, projectId: number): Promise<string>
  • initialized(boolean) - unambiguously determine that the settings have been set

  • projectFee(number) - the amount of fee

  • projectId(number) - unique number of project

usage

//...

(async () => {
    const transaction = await papayaInteraction.setDefaultSettings(
        true,
        10,
        0
    )
})()

setSettingsForUser

description

The settings of a specific user allow you to set up the fee more precisely in relation to a specific wallet, this is necessary, for example, in cases of interaction with opinion leaders

setSettingsForUser(user: string, initialized = true, projectFee: number, projectId: number): Promise<string>

parameters

  • user(string) - address of certain user

  • initialized(boolean) - unambiguously determine that the settings have been set

  • projectFee(number) - the amount of fee

  • projectId(number) - unique number of project

usage

//...

(async () => {
    const transaction = await papayaInteraction.setSettingsForUser(
        "0x1234567890123456789012345678901234567890",
        true,
        20,
        0
    )
})()

deposit

description

Allows depositing funds into the contract. To use this method, you must first approve the necessary amount of tokens for the Papaya contract.

deposit(amount: number, isPermit2 = false): Promise<string>

parameters

  • amount(number) - amount of funds

  • isPermit2(boolean) - a flag indicating the specificity of the token

This flag is usually set to false, due to the fact that there are quite a few tokens with permit2 support

usage

//...

(async () => {
    const transaction = await papayaInteraction.deposit(1*(10**18), false)
})()

depositFor

description

This method is used if you need to deposit funds into another user's account, this is necessary in case of integration of third-party paid systems, for example fiat on ramp

depositFor(amount: number, to: string, isPermit2 = false): Promise<string>

parameters

  • amount(number) - amount of funds

  • to(string) - address of receiever

  • isPermit2(boolean) - a flag indicating the specificity of the token

usage

//...

(async () => {
    const transaction = await papayaInteraction.depositFor(
        1*(10**18),
        "0x1234567890123456789012345678901234567890",
        false
    )
})()

withdraw

description

Allows withdrawing your funds at any time. When this method is called, your balance will be synchronized, and you can withdraw any available amount.

withdraw(amount: number): Promise<string>

parameters

  • amount (number) - amount of funds

usage

//...

(async () => {
    const transaction = await papayaInteraction.withdraw(1*(10**18))
})()

withdrawTo

description

This method is used if you want to withdraw your funds to another wallet

withdrawTo(to: string, amount: number): Promise<string>

parameters

  • to(string) - address of receiver

  • amount(number) - amount of funds

usage

//...

(async () => {
    const transaction = await papayaInteraction.withdrawTo(
    "0x1234567890123456789012345678901234567890",
    1*(10**18)
    )
})()

pay

description

Allows sending funds without using the subscription mechanism, similar to the classic transfer method.

pay(to: string, amount: number): Promise<string>

parameters

  • to(string) - address of receiver

  • amount(number) - amount of funds

usage

//...

(async () => {
    const transaction = await papayaInteraction.pay(
    "0x1234567890123456789012345678901234567890",
    1*(10**18)
    )
})()

subscribe

description

Responsible for creating and modifying subscriptions. Since it is impossible to efficiently predefine costs, users need to specify how much they want to pay monthly, for example.

subscribe(author: string, subscriptionRate: number, projectId: number): Promise<string>

parameters

  • author(string) - address of certain author

  • subscriptionRate(number) - the size of a per-second subscription

  • projectId(number) - unique number of project

usage

//...

(async () => {
    const transaction = await papayaInteraction.subscribe(
        "0x1234567890123456789012345678901234567890",
        1*(10**18),
        0
    )
})()

unsubscribe

description

Responsible for disabling a subscription. This method can be called at any time to stop payments from an individual user.

unsubscribe(author: string): Promise<string>

parameters

  • author(string) - address of certain author

usage

//...

(async () => {
    const transaction = await papayaInteraction.unsubscribe(
        "0x1234567890123456789012345678901234567890"
    )
})()

liquidate

description

parameters

liquidate(target: string): Promise<string>
  • target(string) - address of user that would be liquidated

usage

//...

(async () => {
    const transaction = await papayaInteraction.liquidate(
        "0x1234567890123456789012345678901234567890"
    )
})()

This method gives you access to liquidation mechanism. More information

ethers.js
here