Search code examples
wavesplatformride

Payment.assetId data type


I'm trying to deal with the example https://docs.wavesplatform.com/en/smart-contracts/ride4dapps/examples.html and change it a bit to extend it to any types of assets. It is not clear what type of data is returned to the function and how to bring it to the string so that it can be written to the state later.

let payment = match(i.payment) { #even none or exact amount of the attached payment(InvokeScriptTransaction).
    case p : AttachedPayment => p
    case _ => throw("You have to provide a payment to deposit")
  }

let assetId = toBase58String(payment.assetId)

Solution

  • If you try to compile your code you'll see an error like below

    Compilation failed: Non-matching types: expected: ByteVector, actual: UNION(ByteVector|Unit) in 2176-2207
    

    Every time when the value of the variable is ambiguous you have to extract the value using extract function. In this case, you can get Unit (which represents Waves assetId) or byteVector (assetId of other assets), so you have to extract. The code below will work for your case:

    let assetId = toBase58String(extract(payment.assetId))