waves_logo Docs
  • Ride Programming Language
    Ride Programming Language
  • Getting Started
    Getting Started
  • Syntax Basics
    • Directives
      Directives
    • Definition
      Definition
    • Expression
      Expression
    • Constant
      Constant
    • Variable
      Variable
    • Function
      Function
    • Exception
      Exception
    • Comment
      Comment
    Syntax Basics
  • Script Types
    • dApp Script
      • Annotations
        Annotations
      • Callable Function
        Callable Function
      • Verifier Function
        Verifier Function
      dApp Script
    • Account Script
      Account Script
    • Asset Script
      Asset Script
    Script Types
  • Standard Library
    • Version 5: What’s New
      Version 5: What’s New
    Standard Library
  • Data types
    • Any
      Any
    • BigInt
      BigInt
    • Boolean
      Boolean
    • ByteVector
      ByteVector
    • Int
      Int
    • String
      String
    • Unit
      Unit
    • List
      List
    • Tuple
      Tuple
    • Union
      Union
    Data types
  • Structures
    • Script Actions
      • BinaryEntry
        BinaryEntry
      • BooleanEntry
        BooleanEntry
      • Burn
        Burn
      • DeleteEntry
        DeleteEntry
      • IntegerEntry
        IntegerEntry
      • Issue
        Issue
      • Lease
        Lease
      • LeaseCancel
        LeaseCancel
      • Reissue
        Reissue
      • ScriptTransfer
        ScriptTransfer
      • SponsorFee
        SponsorFee
      • StringEntry
        StringEntry
      Script Actions
    • Common Structures
      • Address
        Address
      • Alias
        Alias
      • Asset
        Asset
      • AssetPair
        AssetPair
      • AttachedPayment
        AttachedPayment
      • BalanceDetails
        BalanceDetails
      • BlockInfo
        BlockInfo
      • Invocation
        Invocation
      • Order
        Order
      • Transfer
        Transfer
      Common Structures
    • Transaction Structures
      • BurnTransaction
        BurnTransaction
      • CreateAliasTransaction
        CreateAliasTransaction
      • DataTransaction
        DataTransaction
      • ExchangeTransaction
        ExchangeTransaction
      • GenesisTransaction
        GenesisTransaction
      • InvokeScriptTransaction
        InvokeScriptTransaction
      • IssueTransaction
        IssueTransaction
      • LeaseCancelTransaction
        LeaseCancelTransaction
      • LeaseTransaction
        LeaseTransaction
      • MassTransferTransaction
        MassTransferTransaction
      • ReissueTransaction
        ReissueTransaction
      • SetAssetScriptTransaction
        SetAssetScriptTransaction
      • SetScriptTransaction
        SetScriptTransaction
      • SponsorFeeTransaction
        SponsorFeeTransaction
      • TransferTransaction
        TransferTransaction
      • UpdateAssetInfoTransaction
        UpdateAssetInfoTransaction
      Transaction Structures
    Structures
  • Built-in Variables
    Built-in Variables
  • Built-in Functions
    • Account Data Storage Functions
      Account Data Storage Functions
    • Blockchain Functions
      Blockchain Functions
    • Byte Array Functions
      Byte Array Functions
    • Converting Functions
      Converting Functions
    • dApp-to-dApp Invocation Function
      dApp-to-dApp Invocation Function
    • Data Transaction Functions
      Data Transaction Functions
    • Decoding Functions
      Decoding Functions
    • Encoding Functions
      Encoding Functions
    • Exception Functions
      Exception Functions
    • Hashing Functions
      Hashing Functions
    • List Functions
      List Functions
    • Math Functions
      Math Functions
    • String Functions
      String Functions
    • Union Functions
      Union Functions
    • Verification Functions
      Verification Functions
    Built-in Functions
  • Operators
    Operators
  • Pattern Matching: match-case
    Pattern Matching: match-case
  • Iterations with FOLD<N>
    Iterations with FOLD<N>
  • dApp-to-dApp Invocation
    dApp-to-dApp Invocation
  • Limitations
    • Complexity
      Complexity
    • Data Weight
      Data Weight
    Limitations
  • Version 6 (Testnet, Stagenet)
    • Callable Function
      Callable Function
    • Structures
      • Invocation
        Invocation
      Structures
    • Built-in Functions
      • Byte Array Functions
        Byte Array Functions
      • Converting Functions
        Converting Functions
      • Hashing Functions
        Hashing Functions
      • Math Functions
        Math Functions
      • String Functions
        String Functions
      • Verification Functions
        Verification Functions
      Built-in Functions
    • Limitations
      Limitations
    Version 6 (Testnet, Stagenet)
  • Previous Versions: 4 and 3
    • Callable Function
      Callable Function
    • Data types
      • Boolean
        Boolean
      • ByteVector
        ByteVector
      • Int
        Int
      • String
        String
      • Unit
        Unit
      • List
        List
      • Tuple
        Tuple
      • Union
        Union
      Data types
    • Structures
      • Script Actions
        • BinaryEntry (v4)
          BinaryEntry (v4)
        • BooleanEntry (v4)
          BooleanEntry (v4)
        • Burn (v4)
          Burn (v4)
        • DataEntry (v3)
          DataEntry (v3)
        • DeleteEntry (v4)
          DeleteEntry (v4)
        • IntegerEntry (v4)
          IntegerEntry (v4)
        • Issue (v4)
          Issue (v4)
        • Reissue (v4)
          Reissue (v4)
        • ScriptTransfer (v3 and v4)
          ScriptTransfer (v3 and v4)
        • SponsorFee (v4)
          SponsorFee (v4)
        • StringEntry (v4)
          StringEntry (v4)
        Script Actions
      • Script Results (v3)
        • ScriptResult
          ScriptResult
        • TransferSet
          TransferSet
        • WriteSet
          WriteSet
        Script Results (v3)
      • Common Structures
        • Address
          Address
        • Alias
          Alias
        • Asset
          Asset
        • AssetPair
          AssetPair
        • AttachedPayment
          AttachedPayment
        • BalanceDetails
          BalanceDetails
        • BlockInfo
          BlockInfo
        • Invocation
          Invocation
        • Order
          Order
        • Transfer
          Transfer
        Common Structures
      • Transaction Structures
        • BurnTransaction
          BurnTransaction
        • CreateAliasTransaction
          CreateAliasTransaction
        • DataTransaction
          DataTransaction
        • ExchangeTransaction
          ExchangeTransaction
        • GenesisTransaction
          GenesisTransaction
        • InvokeScriptTransaction
          InvokeScriptTransaction
        • IssueTransaction
          IssueTransaction
        • LeaseCancelTransaction
          LeaseCancelTransaction
        • LeaseTransaction
          LeaseTransaction
        • MassTransferTransaction
          MassTransferTransaction
        • ReissueTransaction
          ReissueTransaction
        • SetAssetScriptTransaction
          SetAssetScriptTransaction
        • SetScriptTransaction
          SetScriptTransaction
        • SponsorFeeTransaction
          SponsorFeeTransaction
        • TransferTransaction
          TransferTransaction
        • UpdateAssetInfoTransaction
          UpdateAssetInfoTransaction
        Transaction Structures
      Structures
    • Built-in Variables
      Built-in Variables
    • Built-in Functions
      • Account Data Storage Functions
        Account Data Storage Functions
      • Blockchain Functions
        Blockchain Functions
      • Byte Array Functions
        Byte Array Functions
      • Converting Functions
        Converting Functions
      • Data Transaction Functions
        Data Transaction Functions
      • Decoding Functions
        Decoding Functions
      • Encoding Functions
        Encoding Functions
      • Exception Functions
        Exception Functions
      • Hashing Functions
        Hashing Functions
      • List Functions
        List Functions
      • Math Functions
        Math Functions
      • String Functions
        String Functions
      • Union Functions
        Union Functions
      • Verification Functions
        Verification Functions
      Built-in Functions
    • Operators
      Operators
    • Limitations
      • Data Weight
        Data Weight
      Limitations
    Previous Versions: 4 and 3
  • Import Libraries
    Import Libraries
  • Ride Components
    Ride Components
      • English
      • Русский
      On this page
        • invoke
          • Reentrancy Restriction
          • Parameters
          • Example
        • reentrantInvoke
      waves_logo Docs

          # dApp-to-dApp Invocation Functions

          Name Description Complexity
          invoke Invokes a dApp callable function, with reentrancy restriction 75
          reentrantInvoke Invokes a dApp callable function, without reentrancy restriction 75

          # invoke

          Invokes a dApp callable function, with reentrancy restriction.

          invoke(dApp: Address|Alias, function: String, arguments: List[Any], payments: List[AttachedPayments]): Any
          

          Any means any valid type. You can extract a particular type from it using the match ... case operator, see the example.

          The invoke function can be used by a callable function of a dApp script, but not by a verifier function, account script or asset script.

          Via the invoke function, the callable function can invoke a callable function of another dApp, or another callable function of the same dApp, or even itself, and then use the invocation results in subsequent operations. For details, see the dApp-to-dApp Invocation article.

          💡 To ensure executing callable functions and applying their actions in the right order, initialize a strict variable by the return value of an invoke function.

          The invocation can contain payments that will be transferred from the balance of the parent dApp to the balance of the invoked dApp. Payments are forbidden if the dApp invokes itself.

          If a payment token is a smart asset, the asset script verifies the invoke as if it was InvokeScriptTransaction with the following fields:

          • dApp, payments, function, args indicated in the invoke function;
          • sender, senderPublicKey of the dApp that performs the invocation;
          • id, timestamp, fee, feeAssetId indicated in the original Invoke Script transaction;
          • version = 0;

          If the asset script denies the action, the Invoke Script transaction is either discarded or saved on the blockchain as failed, see the Transaction Validation.

          # Reentrancy Restriction

          The invocation stack generated by the invoke function must not contain invocations of the parent dApp after invocation of another dApp.

          Let the parent dApp A invokes dApp B using the invoke function. Regardless of whether dApp B uses invoke or reentrantInvoke, the following invocation stacks will fail:

          → dApp A
             → dapp B
                 → dApp A
          
          → dApp A
             → dapp B
                → dApp C
                   → dApp A
          

          The following invocation stacks are valid:

          → dApp A
             → dapp A
                → dapp A
          
          → dApp N
             → dapp A
             → dApp A
          
          → dapp N
             → dapp A
                → dapp B
             → dapp B
                → dapp A
                → dapp C
          

          # Parameters

          Parameter Description
          dApp: Address|Alias Address or alias of a dApp to invoke
          function: String|Unit Name of a callable function. unit for a default function invocation
          arguments: List[Any] Parameters of a callable function
          payments: List[AttachedPayment] Payments to transfer from the parent dApp to the invoked dApp, up to 10

          # Example

          A user sends an Invoke Script transaction that invokes the callable function foo of dApp1.

          The foo function invokes the bar function of dApp2 passing the number a and attaching a payment of 1 USDN.

          The bar function transfers 1 WAVES to dApp1 and returns the doubled number a.

          The foo function writes to dApp1 data storage:

          • the value returned by bar,
          • the new balance of dApp2 (reduced by 1 WAVES transferred to dApp1).

          dApp1:

          {-# STDLIB_VERSION 5 #-}
          {-# CONTENT_TYPE DAPP #-}
          {-# SCRIPT_TYPE ACCOUNT #-}
          
          @Callable(i)
          func foo(dapp2: String, a: Int, key1: String, key2: String) = {
             strict res = invoke(addressFromStringValue(dapp2),"bar",[a],[AttachedPayment(base58'DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p',1000000)])
             match res {
               case r : Int => 
                (
                   [
                     IntegerEntry(key1, r),
                     IntegerEntry(key2, wavesBalance(addressFromStringValue(dapp2)).regular)
                   ],
                   unit
                )
               case _ => throw("Incorrect invoke result") 
             }
          }
          

          dApp2:

          {-# STDLIB_VERSION 5 #-}
          {-# CONTENT_TYPE DAPP #-}
          {-# SCRIPT_TYPE ACCOUNT #-}
          
          @Callable(i)
          func bar(a: Int) = {
             (
                [
                   ScriptTransfer(i.caller, 100000000, unit)
                ],
                a*2
             )
          }
          

          # reentrantInvoke

          Invokes a dApp callable function. The only difference from the invoke function is that there is no reentrancy restriction for the parent dApp that uses reentrantInvoke.

          However, if the parent dApp is invoked again and this time uses the invoke function, the parent dApp cannot be invoked again in this invocation stack.

          For example, the invocation stack

          → dApp A
             → dapp B
                → dApp A
                   → dApp C
                      → dApp A
          
          • is valid if dApp A invokes both dApp B and dApp C via the reentrantInvoke function;
          • fails if dApp A invokes dApp B via the reentrantInvoke function and invokes dApp C via the invoke function.
          reentrantInvoke(dApp: Address|Alias, function: String, arguments: List[Any], payments: List[AttachedPayments]): Any
          
          Converting Functions
          Data Transaction Functions
          Converting Functions
          Data Transaction Functions