简体   繁体   中英

How can I create that waves smart contracts and assets with JS?

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 ).

Actually yes you're right, there are no smart contracts like in Ethereum but there are smart accounts and smart assets. Basically the Waves smart account can check if the transaction meets certain conditions which are defined in a script before the transaction is submitted to be included in the next generated block. So you can use a script on your account that will allow you to control all outgoing transactions in different use cases including 2FA, Multisig, escrow and oracles among others (you can do that by using SetScript Transaction ). The concept of smart assets is simple, the smart assets are assets with an attached script which validates every transaction within that asset (you can do that by using SetAssetScript Transaction ).

If you're interested to read more, you can check smart accounts and smart assets sections. You can start creating a smart account or smart assets via Waves IDE , Here is a simple smart asset example to make a whitelist use case:

let whiteListAccount = tx.sender
match tx {
   case tx : TransferTransaction =>
   let recipient = toBase58String(addressFromRecipient(tx.recipient).bytes)
   isDefined(getInteger(whiteListAccount, recipient))
   case _ => true
}

And here is a simple smart account example for 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

You can find more examples in Waves IDE , Waves documentation and in Github . The Waves API JS library is outdated, you can use Waves Transactions for that purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM