简体   繁体   English

如何使用JS创建智能合约和资产?

[英]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? 我试图为Waves Platform编写智能合约,据我所知,没有智能合约,如以太坊,有智能账户和智能资产,可以验证交易,但我怎样才能创建智能合约和资产? I didn't find methods in the JS library ( https://github.com/wavesplatform/waves-api ). 我没有在JS库中找到方法( 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. 基本上, Waves智能帐户可以检查事务是否满足在提交事务以包含在下一个生成的块中之前在脚本中定义的某些条件。 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 ). 因此,您可以在帐户上使用一个脚本,该脚本允许您控制不同用例中的所有传出事务,包括2FA,Multisig,托管和oracles等(您可以使用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 ). 智能资产的概念很简单,智能资产是带有附加脚本的资产,该脚本验证该资产中的每个事务(您可以通过使用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: 您可以通过Waves IDE开始创建智能帐户智能资产 。以下是制作白名单用例的简单智能资产示例:

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: 以下是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 . 您可以在Waves IDEWaves文档Github中找到更多示例。 The Waves API JS library is outdated, you can use Waves Transactions for that purpose. Waves API JS库已过时,您可以使用Waves Transactions进行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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