waves_logo Docs
  • Overview
    Overview
  • How-to Guides
    • Reading Blockchain Data
      Reading Blockchain Data
    • Creating & Broadcasting Transactions
      Creating & Broadcasting Transactions
    • Tokenization
      Tokenization
    • Airdrop
      Airdrop
    • Payments
      Payments
    • Exchange Tokens
      Exchange Tokens
    • Simple Voting
      Simple Voting
    • List as argument
      List as argument
    How-to Guides
  • Waves Smart Contracts
    Waves Smart Contracts
  • dApp
    • Creating & Launching dApp
      Creating & Launching dApp
    dApp
  • Smart Account
    • Creating smart account
      Creating smart account
    • Creating and deploying a script manually
      Creating and deploying a script manually
    • Video tutorials
      • Introduction to the Waves blockchain, Waves Smart Accounts and Waves Smart Assets
        Introduction to the Waves blockchain, Waves Smart Accounts and Waves Smart Assets
      • Waves Smart Account with multisignature
        Waves Smart Account with multisignature
      • Waves Smart Account with escrow service
        Waves Smart Account with escrow service
      • Creating multisignature account via Waves IDE tools
        Creating multisignature account via Waves IDE tools
      • Creating multisignature account via Waves Client
        Creating multisignature account via Waves Client
      • Waves console explained
        Waves console explained
      Video tutorials
    Smart Account
  • Smart Asset
    Smart Asset
  • Developer Tools
    • Waves IDE
      Waves IDE
    • Visual Studio Code Extension
      Visual Studio Code Extension
    • Surfboard
      Surfboard
    • Ride REPL
      Ride REPL
    Developer Tools
  • Signer ◆
    Signer ◆
  • Waves API
    • Data Service API
      Data Service API
    • Node REST API
      Node REST API
    • Node gRPC Server
      Node gRPC Server
    • Blockchain Updates
      Blockchain Updates
    Waves API
  • Client Libraries
    • Waves C#
      • Install SDK
        Install SDK
      • Run Code Sample
        • Send Transactions
          Send Transactions
        • Use Crypto Utilities
          Use Crypto Utilities
        • Interact With Node
          Interact With Node
        • Set Up Smart Contracts
          Set Up Smart Contracts
        Run Code Sample
      Waves C#
    • Gowaves
      • Install SDK
        Install SDK
      Gowaves
    • WavesJ
      • Install SDK
        Install SDK
      WavesJ
    • Ts-lib-crypto
      • Install SDK
        Install SDK
      Ts-lib-crypto
    • Waves-PHP
      • Install SDK
        Install SDK
      Waves-PHP
    • Waves-python
      • Install SDK
        Install SDK
      Waves-python
    • Waves-rust
      • Install SDK
        Install SDK
      Waves-rust
    Client Libraries
      • English
      • Русский
      On this page
        • Attaching an Account Script to an Account
        • Account Script Structure
        • Expression
        • Smart accounts and trading
        • Smart Account Script Examples
        • Smart Account Fees
        • Waves Tech Blog Articles
      waves_logo Docs

          # What is Smart Account

          The functionality of a regular account only allows you to verify that the transaction released from it was actually sent from this account.

          Attaching an account script to an account extends its functionality. It enables checking outgoing transactions for compliance with the conditions specified in the script. An account with a script attached to it is called a smart account. Only those transactions that have been validated can be sent from the smart account. For example, an account owner can set a rule according to which transactions can be sent from the address only if the blockchain height exceeds N. Another example — an account owner can allow sending only certain types of transactions. Or disable any validation other than the rule that all transactions sent from the address should be considered valid.

          The following parameters can be used for checks:

          • Transaction proofs or signature.
          • The current blockchain height.
          • Arbitrary data existing in the blockchain, for example, oracle data.

          # Attaching an Account Script to an Account

          As we mentioned before, an account without a script validates transactions using the transaction validation mechanism. The operation of this mechanism is equivalent to the operation of the following script:

          sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPk)
          

          To attach your own script to an account, you need to send a set script transaction from it. Only one script can be attached to an account. “Detaching” a script from a smart account or replacing the old account script with a new one is possible unless the old script forbids it. To "detach" a script or replace it with a new one, you will need to send a new set script transaction. The transaction fee for setting the script is 0.01 WAVES.

          # Account Script Structure

          # Directive

          The directive should be placed at the very beginning of the script. Review the example directive:

          {-# STDLIB_VERSION 8 #-}
          {-# CONTENT_TYPE EXPRESSION #-}
          {-# SCRIPT_TYPE ACCOUNT #-}
          

          The given directive consists of three annotations and provides the compiler with the following information:

          • the script uses version 8 of the library of standard functions
          • the type of script content is Expression
          • this variable type will be Address.

          # Expression

          The expression checks the transactions sent by the account for compliance with the specified conditions. If the conditions are not met, the transaction will not be sent. Possible results of the expression are

          • true (transaction is allowed)
          • false (transaction is not allowed)
          • error

          # Smart accounts and trading

          Along with transactions, smart contracts allow to set rules (limitations) for the account trading operations. Examples of these rules are listed below.

          # Smart Account Script Examples

          # Buying or Selling only BTC

          An account with the script below can make sales transactions only in relation to BTC:

          let cooperPubKey = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'
          let BTCId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'
          match tx {
             case o: Order =>
                sigVerify(o.bodyBytes, o.proofs[0], cooperPubKey ) && (o.assetPair.priceAsset == BTCId || o.assetPair.amountAsset == BTCId)
             case _ => sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey )
          }
          

          # Purchase of a Certain Asset

          The script below allows making purchases from your account

          • only a given asset
          • for a given price only
          • only for WAVES
          let myAssetId = base58'8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS'
          let cooperPubKey = base58'BVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'
            
          match tx {
             case o: Order =>
                sigVerify(o.bodyBytes, o.proofs[0], cooperPubKey ) && o.assetPair.priceAsset == null && o.assetPair.amountAsset == myAssetId && o.price == 500000 && o.amount == 1000 && o.orderType == Buy
             case _ => sigVerify(tx.bodyBytes, tx.proofs[0], cooperPubKey )
          }
          

          # Smart Account Fees

          If the complexity of the account script exceeds the sender complexity threshold, the minimum fee for each transaction sent from the smart account is increased by 0.004 WAVES.

          # Waves Tech Blog Articles

          • The Hitchhiker’s Guide to Waves Smart Contracts. Part 1 (14 September 2018)
          • The Hitchhiker’s Guide to Waves Smart Contracts. Part 2 (18 September 2018)
          • Stateful Smart Accounts. Part 1  (17 September 2018)
          • Stateful Smart Accounts. Part 2 (3 October 2018)
          • Application of Waves Smart Accounts: from Auctions to Customer Loyalty Schemes (2 March 2019)
          • Application of Waves Smart Accounts and Smart Assets for Financial Instruments (15 March 2019)
          Creating & Launching dApp
          Creating smart account
          Creating & Launching dApp
          Creating smart account