Questions about smart contracts developing

Hello, I am new to Waves! I want to make a smart contract that would compare the attachments of two incoming transactions and if they match, then send the funds to the first sender, but if the not match, then send funds to the second sender.
This is similar to a game where the first player makes a number, and the second player guesses.

I have two questions.

  1. How can a smart contract identify a transaction? That is, how does a smart contract can understand that a transaction came from a player who makes a number or from a player who guesses?

  2. Can a smart account send funds to the winner automatically or a smart contract can only allow the winner to withdraw funds from the smart account?

Thanks in advance!

For example, you can use Attachment field:
https://wavesexplorer.com/tx/4qVvCqCufmH66JHn6sRp7BwwYNkb4uZwDqXX5NuC7Q8m

Thanks, brox! I understand that i can use attachment field of incoming transactions, but my questions are not about that.

Hi I found a script for a lottery ,

Is it possible to check it not working for me

Lottery Account contract

Lottery account pubKey

let lotto = extract(tx.senderPublicKey)

LotteryTicket asset

let lottoTicket = base58’HRKmotB2QJo2j9RpY7CRwciKvp7QSwPMwvzTKo4yVmej’

Signature check for other TXs

let txSig = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)

match (tx) {
case o:Order =>
# If price asset is Waves and Asset is LottoTicket then proceed with lottery
if(!isDefined(o.assetPair.priceAsset) && o.assetPair.amountAsset == lottoTicket) then {
# Match if price is 1 wavelet (Price is 100000000 because Asset decimals == 0)
# to take back lottery ticket
# if not check β€œRandomizer 0.1” results
if(o.price == 100000000) then {
txSig
} else {
# Randomizer 0.1
# Get first byte from Matcher proof, convert to Base58 string and compare to lucky ones
let randomByte = take(tx.proofs[0], 1)
let rbs = toBase58String(randomByte)
# List of lucky bytes from 0 to 120 as Base58 strings
(rbs == β€œ1” || rbs == β€œ2” || rbs == β€œ3” || rbs == β€œ4” || rbs == β€œ5” || rbs == β€œ6” || rbs == β€œ7” || rbs == β€œ8” || rbs == β€œ9” || rbs == β€œA” || rbs == β€œB” || rbs == β€œC” || rbs == β€œD” || rbs == β€œE” || rbs == β€œF” || rbs == β€œG” || rbs == β€œH” || rbs == β€œJ” || rbs == β€œK” || rbs == β€œL” || rbs == β€œM” || rbs == β€œN” || rbs == β€œP” || rbs == β€œQ” || rbs == β€œR” || rbs == β€œS” || rbs == β€œT” || rbs == β€œU” || rbs == β€œV” || rbs == β€œW” || rbs == β€œX” || rbs == β€œY” || rbs == β€œZ” || rbs == β€œa” || rbs == β€œb” || rbs == β€œc” || rbs == β€œd” || rbs == β€œe” || rbs == β€œf” || rbs == β€œg” || rbs == β€œh” || rbs == β€œi” || rbs == β€œj” || rbs == β€œk” || rbs == β€œm” || rbs == β€œn” || rbs == β€œo” || rbs == β€œp” || rbs == β€œq” || rbs == β€œr” || rbs == β€œs” || rbs == β€œt” || rbs == β€œu” || rbs == β€œv” || rbs == β€œw” || rbs == β€œx” || rbs == β€œy” || rbs == β€œz” || rbs == β€œ21” || rbs == β€œ22” || rbs == β€œ23” || rbs == β€œ24” || rbs == β€œ25” || rbs == β€œ26” || rbs == β€œ27” || rbs == β€œ28” || rbs == β€œ29” || rbs == β€œ2A” || rbs == β€œ2B” || rbs == β€œ2C” || rbs == β€œ2D” || rbs == β€œ2E” || rbs == β€œ2F” || rbs == β€œ2G” || rbs == β€œ2H” || rbs == β€œ2J” || rbs == β€œ2K” || rbs == β€œ2L” || rbs == β€œ2M” || rbs == β€œ2N” || rbs == β€œ2P” || rbs == β€œ2Q” || rbs == β€œ2R” || rbs == β€œ2S” || rbs == β€œ2T” || rbs == β€œ2U” || rbs == β€œ2V” || rbs == β€œ2W” || rbs == β€œ2X” || rbs == β€œ2Y” || rbs == β€œ2Z” || rbs == β€œ2a” || rbs == β€œ2b” || rbs == β€œ2c” || rbs == β€œ2d” || rbs == β€œ2e” || rbs == β€œ2f” || rbs == β€œ2g” || rbs == β€œ2h” || rbs == β€œ2i” || rbs == β€œ2j” || rbs == β€œ2k” || rbs == β€œ2m” || rbs == β€œ2n” || rbs == β€œ2o” || rbs == β€œ2p” || rbs == β€œ2q” || rbs == β€œ2r” || rbs == β€œ2s” || rbs == β€œ2t” || rbs == β€œ2u” || rbs == β€œ2v” || rbs == β€œ2w” || rbs == β€œ2x” || rbs == β€œ2y” || rbs == β€œ2z” || rbs == β€œ31” || rbs == β€œ32” || rbs == β€œ33” || rbs == β€œ34” || rbs == β€œ35”)
}
} else {
txSig
}
case _ => txSig
}

The expression for the list of lucky bytes can not be parsed in this way.

For now, smart contracts can validate outgoing transactions only, not incoming transactions.
But in testnet a new big feature is available - Ride4DApps. This adds new features to the RIDE language and adds new transaction type InvokeScriptTransaction.
So, you can create a new DApp contract that receives InvokeScript and sends funds for a winner when some conditions are met.
Please note that this functionality is currently available only on testnet. It is expected to appear on mainnet around June.

1 Like