Create resource with script


#1

Tutorial create resource with script?


#2

do you mean smart account?


#3

I do not know, I still have to study a lot, but everything seems so chaotic.
I want to get a smart asset with an empty script.
After inserting the script


#4

Smart asset.
Create a token that is not negotiable in dex.
At the beginning with an empty script, update it in a second time.


#5

Hi,

What instruments are you using? Will it be OK if I show you how to do this using WavesCS?


#6

I think so.
Do you need information to know what I want to get exactly?


#7

I need to create a token and set a price in the dex. Then with the script block the negotiation in the dex.
This token will be used to buy, sell, pay, be paid for goods or services of various kinds.
Can someone help me?


#8

There’re two possibilities with the same result:

  1. Issue an asset with the script ‘true’ and change the script later (if at the moment you don’t know what script you’re gonna set to your asset):
var node = new Node();
PrivateKeyAccount MyAccount = PrivateKeyAccount.CreateFromSeed("any seed here", AddressEncoding.TestNet);
Console.WriteLine(MyAccount.Address);

// use faucet to fill the account: https://testnet.wavesexplorer.com/faucet 
var compiledScript = node.CompileScript("true");
Asset smartAsset = node.IssueAsset(MyAccount, "AssetName",  "asset description", 100, 4,  true, compiledScript);

// later you're able to do the following:

var script = "your script here";
var compiledScript2 = node.CompileScript(script); 
var setAssetScriptTransaction = new SetAssetScriptTransaction(MyAccount.PublicKey, smartAsset, compiledScript2, 'T', 1); 
setAssetScriptTransaction.Sign(MyAccount);
node.Broadcast(setAssetScriptTransaction);
  1. Issue a smart asset which already has the script you want:
var node = new Node();
PrivateKeyAccount MyAccount = PrivateKeyAccount.CreateFromSeed("any seed here", AddressEncoding.TestNet);

var script = "your script here";
var compiledScript = node.CompileScript(script);

Asset smartAsset = node.IssueAsset(MyAccount, "AssetName", "asset description", 100, 4, true, compiledScript);

#9

The following script blocks the negotiation in the dex:

match tx {
  case e: ExchangeTransaction => false
  case _ => true
}

Later you’re able to change the script via SetAssetScriptTransaction.

The following script fixes a price in the dex:

let asset = base58'9jfD2JBLe23XtCCSQoTx5eAW5QCU6Mbxi3r78aNQLcNf'
match tx {
  case e: ExchangeTransaction =>
    e.price == 100 && e.sellOrder.assetPair.priceAsset == asset
  case _ => true
}

Make sure you’ve let yourself to change the script later via specifying " case s : SetAssetScriptTransaction => true" (or “case _ => true” if “case SetAssetScriptTransaction” is not specified).


Setting Exchange Value
#10

How many beautiful things.
A domada, in the script above I read “testnet”, so for now it is possible to do it only in “testnet”?
So no mainnet.


#11

Yes, this feature is activated on testnet now, and it will be released on mainnet soon.


#12

Ok, thank you so much.


#13

I used your code on the test net as it is. I can not exchange everything. Were there any changes in the specifications?


#14

Hi,
Do you mean this script?

match tx {
 case e: ExchangeTransaction => false
 case _ => true
}

If you set this script to your account then your account cannot send any ExchangeTransactions.
If you set this script to your asset then this asset cannot be traded via ExchangeTransactions.

Our ide (https://ide.wavesplatform.com) can help you deploy scripts to your accounts or assets.


#15

Thank you for your reply(:slight_smile:)
I tried this.

I changed asset ID to my asset ID and issued it.


#16

//# MyToken is a Smart Asset.

let startHeight = 1558024
let startPrice = 12000000
let interval = 8766 * 60
let exp = 41760 * 60 * 10
match tx {
case e:ExchangeTransaction =>
let days = (height - startHeight) / interval
if (
if (
if (
e.price >= startPrice * (1 + days * days)
)
then
!isDefined(e.sellOrder.assetPair.priceAsset)
else
false
)
then
exp >= e.sellOrder.expiration - e.sellOrder.timestamp
else
false
)
then
exp >= e.buyOrder.expiration - e.buyOrder.timestamp
else
false
case tx:BurnTransaction => true
case _ => true
}

##################################################
Starting price 0.12
Today sell and buy price 5, tomorrow sell and buy price 3, never below 0.12.
Price increase 8766 hours, should correspond to one year.
Each year should increase price +0.12 of the current price.
Order time 41760 minutes, should be 29 days.
10 should correspond to the minimum quantity that can be exchanged.
What did I say is correct?
I also practice with IDE, many things work and others I don’t understand.


#17

Hi,
timestamps are measured in milliseconds, so 29 days are equal to 29 * 24 * 60 * 60 * 1000 = 41760 * 60 * 1000
Btw, orders cannot live more than 29 days (it’s checked in the consensus), so checking this is excessive.

If you want the price to increase by +0.12 each year, you should change the formula:

let years = (height - startHeight) / interval
e.price >= startPrice * (1 + years)

If you want to specify the minimum quantity that can be exchanged, you have to add an additional check, something like this:

e.amount >= 10

Note that the amount is measured in smallest asset’s units, so if your asset has 8 decimals then 10 asset corresponds to the amount=1’000’000’000.

The following code would do something similar to what you described:

let startHeight = 1558024
let startPrice = 12000000
let interval = 8766 * 60
let exp = 41760 * 60 * 1000

match tx {
    case e:ExchangeTransaction =>
        let years = (height - startHeight) / interval

          e.price >= startPrice * (1 + years)
          && !isDefined(e.sellOrder.assetPair.priceAsset)
          && e.amount >= 10
    case _ => true
}

#18

Yes 8 decimal.
So minimum exchange amount of MyToken 10.00000000, what to do?

Oops, my head …
So with e.amount> = 1000000000, I get minimum MyToken exchange 10.00000000


#19

Yes, this is correct.


#20

Thank you for your availability