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


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