Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NFTDriverClient

A client for managing Drips accounts identified by NFTs.

see

NFTDriver contract.

Hierarchy

  • NFTDriverClient

Index

Constructors

Properties

#driver: NFTDriver
#driverAddress: string
#provider: Provider
#signer: Signer
#txFactory: INFTDriverTxFactory

Accessors

  • get driverAddress(): string
  • get provider(): Provider
  • get signer(): Signer

Methods

  • #getTokenIdFromTxResponse(txResponse: ContractTransaction): Promise<string>
  • approve(tokenAddress: string): Promise<ContractTransaction>
  • Sets the maximum allowance value for the NFTDriver contract over the client's signer tokens for the given ERC20 token.

    throws

    {@link DripsErrors.addressError} if the tokenAddress is not valid.

    Parameters

    • tokenAddress: string

      The ERC20 token address.

      It must preserve amounts, so if some amount of tokens is transferred to an address, then later the same amount must be transferrable from that address. Tokens which rebase the holders' balances, collect taxes on transfers, or impose any restrictions on holding or transferring tokens are not supported. If you use such tokens in the protocol, they can get stuck or lost.

    Returns Promise<ContractTransaction>

    A Promise which resolves to the contract transaction.

  • collect(tokenId: string, tokenAddress: string, transferToAddress: string): Promise<ContractTransaction>
  • Collects the received and already split funds and transfers them from the DripsHub contract to an address.

    The caller (client's signer) must be the owner of the tokenId or be approved to use it.

    throws

    {@link DripsErrors.argumentMissingError} if the tokenId is missing.

    throws

    {@link DripsErrors.addressError} if tokenAddress or transferToAddress is not valid.

    Parameters

    • tokenId: string

      The ID of the token representing the collecting account.

    • tokenAddress: string

      The ERC20 token address.

      It must preserve amounts, so if some amount of tokens is transferred to an address, then later the same amount must be transferrable from that address. Tokens which rebase the holders' balances, collect taxes on transfers, or impose any restrictions on holding or transferring tokens are not supported. If you use such tokens in the protocol, they can get stuck or lost.

    • transferToAddress: string

      The address to send collected funds to.

    Returns Promise<ContractTransaction>

    A Promise which resolves to the contract transaction.

  • createAccount(transferToAddress: string, associatedApp?: string, userMetadata?: UserMetadata[]): Promise<string>
  • Usage of this method is discouraged; use safeCreateAccount whenever possible.

    Creates a new Drips account.

    It will mint a new NFT controlling a new Drips account and transfer its ownership to an address. It also emits user metadata for the new token.

    Important: In Drips, an account "is" a user ID at the protocol level. The minted NFT's ID (token ID) and the user ID controlled by it are always equal.

    This means that anywhere in the SDK, a method expects a user ID parameter, and a token ID is a valid argument.

    throws

    {@link DripsErrors.argumentMissingError} if the transferToAddress is missing.

    throws

    {@link DripsErrors.addressError} if the transferToAddress is not valid.

    throws

    {@link DripsErrors.txEventNotFound} if the expected transaction event is not found.

    Parameters

    • transferToAddress: string

      The address to transfer the minted token to.

    • Optional associatedApp: string

      The name/ID of the app that is associated with the new account. If provided, the following user metadata entry will be appended to the userMetadata list:

      • key: "associatedApp"
      • value: associatedApp.
    • userMetadata: UserMetadata[] = []

      The list of user metadata. Note that a metadata key needs to be 32bytes.

      Tip: you might want to use Utils.UserMetadata.createFromStrings to easily create metadata instances from string inputs.

    Returns Promise<string>

    A Promise which resolves to minted token ID. It's equal to the user ID controlled by it.

  • emitUserMetadata(tokenId: string, userMetadata: UserMetadata[]): Promise<ContractTransaction>
  • Emits the account's metadata. The key and the value are not standardized by the protocol, it's up to the caller to establish and follow conventions to ensure compatibility with the consumers.

    The caller (client's signer) must be the owner of the tokenId or be approved to use it.

    throws

    {@link DripsErrors.argumentError} if any of the metadata entries is not valid.

    Parameters

    • tokenId: string

      The ID of the token representing the emitting account.

    • userMetadata: UserMetadata[]

      The list of user metadata. Note that a metadata key needs to be 32bytes.

      Tip: you might want to use Utils.UserMetadata.createFromStrings to easily create metadata instances from string inputs.

    Returns Promise<ContractTransaction>

    A Promise which resolves to the contract transaction.

  • getAllowance(tokenAddress: string): Promise<bigint>
  • Returns the remaining number of tokens the NFTDriver contract is allowed to spend on behalf of the client's signer for the given ERC20 token.

    throws

    {@link DripsErrors.addressError} if the tokenAddress is not valid.

    Parameters

    • tokenAddress: string

      The ERC20 token address.

      It must preserve amounts, so if some amount of tokens is transferred to an address, then later the same amount must be transferrable from that address. Tokens which rebase the holders' balances, collect taxes on transfers, or impose any restrictions on holding or transferring tokens are not supported. If you use such tokens in the protocol, they can get stuck or lost.

    Returns Promise<bigint>

    A Promise which resolves to the remaining number of tokens.

  • give(tokenId: string, receiverUserId: string, tokenAddress: string, amount: BigNumberish): Promise<ContractTransaction>
  • Gives funds to the receiver. The receiver can collect them immediately.

    The caller (client's signer) must be the owner of the tokenId or be approved to use it.

    throws

    {@link DripsErrors.argumentMissingError} if any of the required parameters is missing.

    throws

    {@link DripsErrors.addressError} if the tokenAddress is not valid.

    throws

    {@link DripsErrors.argumentError} if the amount is less than or equal to 0.

    Parameters

    • tokenId: string

      The ID of the token representing the giving account.

    • receiverUserId: string

      The receiver user ID.

    • tokenAddress: string

      The ERC20 token address.

      It must preserve amounts, so if some amount of tokens is transferred to an address, then later the same amount must be transferrable from that address. Tokens which rebase the holders' balances, collect taxes on transfers, or impose any restrictions on holding or transferring tokens are not supported. If you use such tokens in the protocol, they can get stuck or lost.

    • amount: BigNumberish

      The amount to give (in the smallest unit, e.g., Wei). It must be greater than 0.

    Returns Promise<ContractTransaction>

    A Promise which resolves to the contract transaction.

  • safeCreateAccount(transferToAddress: string, associatedApp?: string, userMetadata?: UserMetadata[]): Promise<string>
  • Creates a new Drips account.

    It will safely mint a new NFT controlling a new Drips account and transfer its ownership to an address. It also emits user metadata for the new token.

    Important: In Drips, an account "is" a user ID at the protocol level. The minted NFT's ID (token ID) and the user ID controlled by it are always equal.

    This means that anywhere in the SDK, a method expects a user ID parameter, and a token ID is a valid argument.

    throws

    {@link DripsErrors.argumentMissingError} if the transferToAddress is missing.

    throws

    {@link DripsErrors.txEventNotFound} if the expected transaction event is not found.

    throws

    {@link DripsErrors.addressError} if the transferToAddress is not valid.

    Parameters

    • transferToAddress: string

      The address to transfer the minted token to.

    • Optional associatedApp: string

      The name/ID of the app that is associated with the new account. If provided, the following user metadata entry will be appended to the userMetadata list:

      • key: "associatedApp"
      • value: associatedApp.
    • userMetadata: UserMetadata[] = []

      The list of user metadata. Note that a metadata key needs to be 32bytes.

      Tip: you might want to use Utils.UserMetadata.createFromStrings to easily create metadata instances from string inputs.

    Returns Promise<string>

    A Promise which resolves to minted token ID. It's equal to the user ID controlled by it.

  • setDrips(tokenId: string, tokenAddress: string, currentReceivers: DripsReceiverStruct[], newReceivers: DripsReceiverStruct[], transferToAddress: string, balanceDelta?: BigNumberish): Promise<ContractTransaction>
  • Sets a Drips configuration for the given account.

    It will transfer funds from the client's signer wallet to the DripsHub contract to fulfill the change of the drips balance.

    The caller (client's signer) must be the owner of the tokenId or be approved to use it.

    throws

    {@link DripsErrors.argumentMissingError} if any of the required parameters is missing.

    throws

    {@link DripsErrors.addressError} if tokenAddress or transferToAddress is not valid.

    throws

    {@link DripsErrors.argumentError} if currentReceivers' or newReceivers' count exceeds the max allowed drips receivers.

    throws

    {@link DripsErrors.dripsReceiverError} if any of the currentReceivers or the newReceivers is not valid.

    throws

    {@link DripsErrors.dripsReceiverConfigError} if any of the receivers' configuration is not valid.

    throws

    {@link DripsErrors.dripsReceiverConfigError} if any of the receivers' configuration is not valid.

    Parameters

    • tokenId: string

      The ID of the token representing the configured account.

    • tokenAddress: string

      The ERC20 token address.

      It must preserve amounts, so if some amount of tokens is transferred to an address, then later the same amount must be transferrable from that address. Tokens which rebase the holders' balances, collect taxes on transfers, or impose any restrictions on holding or transferring tokens are not supported. If you use such tokens in the protocol, they can get stuck or lost.

    • currentReceivers: DripsReceiverStruct[]

      The drips receivers that were set in the last drips update. Pass an empty array if this is the first update.

      Tip: you might want to use DripsSubgraphClient.getCurrentDripsReceivers to easily retrieve the list of current receivers.

    • newReceivers: DripsReceiverStruct[]

      The new drips receivers (max 100). Duplicate receivers are not allowed and will only be processed once. Pass an empty array if you want to clear all receivers.

    • transferToAddress: string

      The address to send funds to in case of decreasing balance.

    • balanceDelta: BigNumberish = 0

      The drips balance change to be applied:

      • Positive to add funds to the drips balance.
      • Negative to remove funds from the drips balance.
      • 0 to leave drips balance as is (default value).

    Returns Promise<ContractTransaction>

    A Promise which resolves to the contract transaction.

  • Sets the account's Splits configuration.

    The caller (client's signer) must be the owner of the tokenId or be approved to use it.

    throws

    {@link DripsErrors.argumentMissingError} if receivers are missing.

    throws

    {@link DripsErrors.argumentError} if receivers' count exceeds the max allowed splits receivers.

    throws

    {@link DripsErrors.splitsReceiverError} if any of the receivers is not valid.

    Parameters

    • tokenId: string

      The ID of the token representing the configured account.

    • receivers: SplitsReceiverStruct[]

      The splits receivers (max 200). Each splits receiver will be getting weight / TOTAL_SPLITS_WEIGHT share of the funds. Duplicate receivers are not allowed and will only be processed once. Pass an empty array if you want to clear all receivers.

    Returns Promise<ContractTransaction>

    A Promise which resolves to the contract transaction.

  • create(provider: Provider, signer: Signer, customDriverAddress?: string): Promise<NFTDriverClient>
  • create(provider: Provider, signer: Signer, customDriverAddress?: string, txFactory?: INFTDriverTxFactory): Promise<NFTDriverClient>
  • Creates a new immutable NFTDriverClient instance.

    throws

    {@link DripsErrors.initializationError} if the client initialization fails.

    Parameters

    • provider: Provider

      The network provider. It cannot be changed after creation.

      The provider must be connected to one of the following supported networks:

      • 'mainnet': chain ID 1
      • 'goerli': chain ID 5
      • 'polygon-mumbai': chain ID 80001
    • signer: Signer

      The singer used to sign transactions. It cannot be changed after creation.

      Important: If the signer is not connected to a provider it will try to connect to the provider, else it will use the signer.provider.

    • Optional customDriverAddress: string

      Overrides the NFTDriver contract address. If it's undefined (default value), the address will be automatically selected based on the provider's network.

    Returns Promise<NFTDriverClient>

    A Promise which resolves to the new client instance.

  • Parameters

    • provider: Provider
    • signer: Signer
    • Optional customDriverAddress: string
    • Optional txFactory: INFTDriverTxFactory

    Returns Promise<NFTDriverClient>

Generated using TypeDoc