How to call "create txfilter" filter from cli?

+2 votes
Hi Team,

I am trying to execute the e.g Transaction filter for a specific Asset in alpha 5 version.

my Syntax is:

filterch: create txfilter filter1 '{"for":"asset1"}' "function filtertransaction(){var tx=getfiltertransaction();if (tx.vout.length<1)return "One output required";}"

Error: Couldn't compile filter code: SyntaxError: Unexpected end of input

Can you please provide the correct syntax for the same also a sample syntax for testtxfilter.

Thanks in advance.
asked Sep 23, 2018 by anonymous

1 Answer

0 votes

Your problem here is with the fact that you're using double quotes to surround the last parameter, but also using double quotes within that parameter to indicate a string.

Since the MultiChain API uses JSON, in general you should use single quotes to surround MultiChain parameters, then use double quotes within those parameters to indicate strings. So:

create txfilter filter1 '{"for":"asset1"}' 'function filtertransaction(){var tx=getfiltertransaction();if (tx.vout.length<1)return "One output required";}'

answered Sep 24, 2018 by MultiChain
Hi, I managed to get the expected result with the answer. May I know what if the code is in a js file and how do we use testtxfilter in that case?

I tried executing the below statement at the directory where the js file is located:
- multichain-cli test1 testtxfilter {} 'js-codetest.js'

but received response:
     "compiled": false,
     "reason": "ReferenceError: js is not defined"
You cannot pass in a JavaScript file name directly to the MultiChain API. Instead, you would need to extract that file's contents to a string, and pass that string to the API.