Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (4.1k points)

I,m trying to write smart contracts for Waves Platform, as far as I understood, there are no smart contracts like in Ethereum, there are smart accounts and smart assets, which can validate transactions, but how can I create that smart contracts and assets? I didn’t find methods in the JS library (https://github.com/wavesplatform/waves-api).

1 Answer

0 votes
by (14.4k points)

As a matter of fact, there are actually no smart contracts but you can find smart assets and smart accounts. Waves Smart Account can be used to check or enquire if the transaction meets certain conditions that are defined in the script before the transaction is submitted for being included in the succeeding block. When you include a script, you will be able to control all outgoing transactions in different use-cases. 

Now coming on to Smart Assets, Smart Assets are those assets that come with an attached script which is used to validate all transactions that pertain to that asset. This configuration can be set up in SetAssetScript Transaction. 

Waves IDE can be used to create Smart Assets. Here's an example: 

let whiteListAccount = tx.sender

match tx {

   case tx : TransferTransaction =>

   let recipient = toBase58String(addressFromRecipient(tx.recipient).bytes)

   isDefined(getInteger(whiteListAccount, recipient))

   case _ => true

}   

Here's another example for creating a Smart Account with 2-3 MultiSig: 

#define public keys

let alicePubKey  = base58'5AzfA9UfpWVYiwFwvdr77k6LWupSTGLb14b24oVdEpMM'

let bobPubKey    = base58'2KwU4vzdgPmKyf7q354H9kSyX9NZjNiq4qbnH2wi2VDF'

let cooperPubKey = base58'GbrUeGaBfmyFJjSQb9Z8uTCej5GzjXfRDVGJGrmgt5cD'

#check whoever provided the valid proof

let aliceSigned  = if(sigVerify(tx.bodyBytes, tx.proofs[0], alicePubKey  )) then 1 else 0

let bobSigned    = if(sigVerify(tx.bodyBytes, tx.proofs[1], bobPubKey    )) then 1 else 0

let cooperSigned = if(sigVerify(tx.bodyBytes, tx.proofs[2], cooperPubKey )) then 1 else 0

#sum up every valid proof to get at least 2

aliceSigned + bobSigned + cooperSigned >= 2

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...