Can you tell me how to use InvokeScriptTransaction


#1

This is an example of the WAVES IDE.
Please tell me how to use InvokeScriptTransaction to execute ‘func divideAmount ()’.

# waves IDE example
let Alice = Address(base58'3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8')
let Bob = Address(base58'3N78bNBYhT6pt6nugc6ay1uW1nLEfnRWkJd')

@Callable(i)
func divideAmount() = {

    let transferAmount = wavesBalance(this) / 2

    TransferSet([
                ScriptTransfer(Alice, transferAmount, unit),
                ScriptTransfer(Bob, transferAmount, unit)
    ])
}

I set a script for my account on the test net.
However, I do not understand that it calls with InvokeScriptTransaction.
thank you for reading.


#2

If you use IDE you can run in the console. It is also available in the JS library (waves-transactions)

broadcast(invokeScript({contractAddress: {CONTRACT_ADDRESS_HERE}), call:{function:"divideAmount",args:[]}, payment: []}))

#3

Thank you for your answer(:slight_smile:)
I use an IDE. WavesIDE is very easy to use. Thank you for the development.

{CONTRACT_ADDRESS_HERE} This is replaced by my contract address. OK?

Then I ran it on the console.

It was an error…

Am I making a mistake?


#4

Could you send an error message please?


#5

Thank you for your answer( :slight_smile: )

SyntaxError
{
loc:
e
message:
Identifier directly after number (1:57)
pos:
57
stack:
+SyntaxError: Identifier directly after number (1:57)↵ at t.M.raise (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:308989)↵ at t.e.readNumber (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:256514)↵ at t.e.getTokenFromCode (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:254217)↵ at t.e.readToken (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:248580)↵ at t.e.nextToken (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:248468)↵ at t.e.next (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:247403)↵ at t.K.parseObj (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:301177)↵ at t.K.parseExprAtom (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:296963)↵ at t.K.parseExprSubscripts (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:292397)↵ at t.K.parseMaybeUnary (https://ide.wavesplatform.com/app.9308a299ff7f33e65e65.bundle.js?5986934670a6670f1771:148:291981)
}


#6

Sorry, I misinformed you, call should look like below:

broadcast(invokeScript({dappAddress: {CONTRACT_ADDRESS_HERE}), call:{function:"divideAmount",args:[]}, payment: []}))

Difference is in the dappAddress instead of contractAddress in the key.


#7

Thanks for the answer.
I tried the code.
The result was the same. Am I wrong?


#8

#9

Also today you have to use “dApp” instead of “dappAddress” field for the InvokeScript.