Structure

Stash offers a very straightforward and easy way to implement a revenue sharing mechanism.
The structure consists of two operations on both contract and API levels:

  1. Revenue share information: All the information of revenue sharing for a particular NFT are processed on-chain by Stash contracts. There are two important data points to be used:
    a. Recipients
    b. Share percentages

  2. Payout transactions: Stash APIs provide endpoints for paying out the recipients involved in a revenue sharing case.

Both these operations are handled within the core class in Stash Renting SDK. The class implements the following two functions for payout operations:

getPayoutRecipients(
      tokenId: number,
      standard: NFTStandard,
      onError: (error: StashError) => void,
    ): Promise<RewardShareRecipient[] | null>

performPayout(
      tokenId: number,
      standard: NFTStandard,
      amount: number,
      paymentToken: string,
      onSuccess: (response: StashResponse) => void,
      onError: (error: StashError) => void,
    ): Promise<ContractTransaction | null>

Accessing Stash Instance

Before performing payout operations, you need to have initialized the core SDK object:

const stash = new Stash(<apiKey>, <signer>, <chain>, <nftContracts>);

Retrieving Revenue Share Information

Information about the revenue share recipients and percentages can be retrieved by calling the function described below:

getPayoutRecipients:

getPayoutRecipients(
      tokenId: number,
      standard: NFTStandard,
      onError: (error: StashError) => void,
    ): Promise<RewardShareRecipient[] | null>;

Parameters

  • tokenId: Token ID of the NFT
  • standard: Standard of the NFT, either E721 or E1155
  • onError: Response callback for failed operations

Response

If any error occurs, information about the failure reason is provided in a StashError object in onError callback.
If the info has been successfully retrieved, it's encapsulated in form of type RewardShareRecipient with the following declaration:

export type RewardShareRecipient = {
    readonly address: string;
    readonly sharePoint: number;
    readonly role: RecipientRole;
};

export enum RecipientRole {
    Player,
    Owner,
    Market,
    Other
};

Performing Payouts

Stash SDK offers a built-in function to perform all the payouts for a particular revenue sharing case, where the payout amounts are calculated based on the total amount & the given revenue share information and the transactions are initiated.

🚧

Custom Payout Logic

It's up to you to use the SDK for payouts or implement your own logic for initiating the transactions. However, it's strongly recommended to stick to the Stash SDK's functions for all the operations in order to ensure data integrity and convenience.

Payouts can be performed by calling the following function:

performPayout:

performPayout(
      tokenId: number,
      standard: NFTStandard,
      amount: number,
      paymentToken: string,
      onSuccess: (response: StashResponse) => void,
      onError: (error: StashError) => void,
    ): Promise<ContractTransaction | null>

Parameters

  • tokenId: Token ID of the NFT
  • standard: Standard of the NFT, either E721 or E1155
  • amount: Total amount to be paid out
  • **paymentToken: Address of ERC20 token which the payout will be made with
  • onSuccess: Response callback for successful operations. Be aware that this callback is getting called multiple times for each single recipient involved in the payout.
  • onError: Response callback for failed operations

Response

ContractTransaction object representing the contract call or null if the transaction fails.