elective-stereophonic
elective-stereophonic
[Nxt Programming / API] Using AMs to trigger actions or services
Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest Stable Nxt Client: Nxt 1.12.2

Author Topic: [Nxt Programming / API] Using AMs to trigger actions or services  (Read 7825 times)

chesslover

  • Jr. Member
  • **
  • Karma: +1/-0
  • Offline Offline
  • Posts: 60
    • View Profile

Hello,

I would like to know programmatically how to use AMs to trigger an action or services or call other code? Same like ETH smart contracts behavior.

And will they also be same in Ardor?

Thanks in advance!
Logged
The Chess Machine: José Raúl Capablanca

forkedchain

  • Ex-Staff Member
  • Hero Member
  • *****
  • Karma: +74/-10
  • Offline Offline
  • Posts: 1190
  • bite me
    • View Profile
Re: [Nxt Programming / API] Using AMs to trigger actions or services
« Reply #1 on: October 28, 2017, 08:31:21 pm »

I believe that only child chains in ardor will support AMs. 
Logged
NXT tips: 2319251 or NXT-8SWM-2224-YKWW-22222

VanBreuk

  • Hero Member
  • *****
  • Karma: +362/-19
  • Offline Offline
  • Posts: 2772
    • View Profile
Re: [Nxt Programming / API] Using AMs to trigger actions or services
« Reply #2 on: October 29, 2017, 11:44:51 pm »

In the Nxt API wiki page you have information about all the requests that could be useful, mostly Phasing (the NXT feature for conditional or deferred transactions execution). Along with other sections like Arbitrary Messages or some of the tools in Account Operations. But it depends on what do you exactly want to achieve.

Note that this information also applies to Ardor, with some new parameters related to child chain ID - https://nxtwiki.org/wiki/Nxt_to_Ardor
Logged
GPG Fingerprint: B020 D1C1 F289 3B2C 3577  9EAD 455D D175 5913 C7F1

blackyblack1

  • Hero Member
  • *****
  • Karma: +165/-82
  • Offline Offline
  • Posts: 1764
    • View Profile
Re: [Nxt Programming / API] Using AMs to trigger actions or services
« Reply #3 on: October 30, 2017, 08:02:02 am »

In order to implement this stuff you will need to maintain a server which checks the NXT blockchain for incoming AMs, decode them and act accordingly.
Logged

chesslover

  • Jr. Member
  • **
  • Karma: +1/-0
  • Offline Offline
  • Posts: 60
    • View Profile
Re: [Nxt Programming / API] Using AMs to trigger actions or services
« Reply #4 on: October 30, 2017, 09:15:47 am »

Thank you guys, actually I am following this article:

Nxt [CORE]: Arbitrary Messages

Quote
However, advanced applications can use this feature to store structured data, such as JSON objects. These can be used to trigger or facilitate services built on top of NXT.

Quote
Essentially, MGW creates a deposit address for the Nxt user account for each of the supported coins. When the user sends coins to that deposit address, MGW delivers to the associated Nxt account the same quantity of coin assets (designated mgwBTC, mgwLTC, etc). Each of these assets represents one coin...The requests to the MGW servers are broadcasted to the Nxt blockchain as Arbitrary Messages.

What I'm after is how to implement the "triggering" programmatically.
Logged
The Chess Machine: José Raúl Capablanca

chesslover

  • Jr. Member
  • **
  • Karma: +1/-0
  • Offline Offline
  • Posts: 60
    • View Profile
Re: [Nxt Programming / API] Using AMs to trigger actions or services
« Reply #5 on: October 30, 2017, 09:30:36 am »

In order to implement this stuff you will need to maintain a server which checks the NXT blockchain for incoming AMs, decode them and act accordingly.

Yes I am familiar with this model, I have used bitcoind's -walletnotify and reactive Java on Ethereum.

https://docs.web3j.io/filters.html
Logged
The Chess Machine: José Raúl Capablanca

blackyblack1

  • Hero Member
  • *****
  • Karma: +165/-82
  • Offline Offline
  • Posts: 1764
    • View Profile
Re: [Nxt Programming / API] Using AMs to trigger actions or services
« Reply #6 on: October 30, 2017, 11:07:21 am »

In order to implement this stuff you will need to maintain a server which checks the NXT blockchain for incoming AMs, decode them and act accordingly.

Yes I am familiar with this model, I have used bitcoind's -walletnotify and reactive Java on Ethereum.

https://docs.web3j.io/filters.html
So what's the problem? Triggering means that your server sees the AM content and reacts accordingly. Use getAccountTransactions call or something like it.
Logged

chesslover

  • Jr. Member
  • **
  • Karma: +1/-0
  • Offline Offline
  • Posts: 60
    • View Profile
Re: [Nxt Programming / API] Using AMs to trigger actions or services
« Reply #7 on: October 30, 2017, 11:38:22 am »

In order to implement this stuff you will need to maintain a server which checks the NXT blockchain for incoming AMs, decode them and act accordingly.

Yes I am familiar with this model, I have used bitcoind's -walletnotify and reactive Java on Ethereum.

https://docs.web3j.io/filters.html
So what's the problem? Triggering means that your server sees the AM content and reacts accordingly. Use getAccountTransactions call or something like it.

I have no problems, I just want to know how it can be implemented re: post #4 above as written in NXTer magazine.
Logged
The Chess Machine: José Raúl Capablanca

VanBreuk

  • Hero Member
  • *****
  • Karma: +362/-19
  • Offline Offline
  • Posts: 2772
    • View Profile
Re: [Nxt Programming / API] Using AMs to trigger actions or services
« Reply #8 on: October 31, 2017, 02:28:13 am »

In order to implement this stuff you will need to maintain a server which checks the NXT blockchain for incoming AMs, decode them and act accordingly.

Yes I am familiar with this model, I have used bitcoind's -walletnotify and reactive Java on Ethereum.

https://docs.web3j.io/filters.html
So what's the problem? Triggering means that your server sees the AM content and reacts accordingly. Use getAccountTransactions call or something like it.

I have no problems, I just want to know how it can be implemented re: post #4 above as written in NXTer magazine.

The Multigateway service mentioned as example in the article was a third party application that worked on top of the Nxt blockchain. Requests were sent including a JSON formatted message in the blockchain, and these were processed by an external application. It would monitor accounts using the Nxt API, and when a transaction including a certain message syntax was received, execute something else. In the Multigateway case, for example, it would send coins from a Bitcoin multisignature wallet to some BTC address, using the Bitcoin daemon.

In principle, using code to monitor a Nxt account for transactions with certain properties should not be complicated. You need to send an http API request to a Nxt node with the details of your query, process the results, and then take whatever action. I had understood you wanted to automatically trigger a transaction within the Nxt blockchain, for instance an asset transfer, when a first transaction is sent. For that you can look into phasing, but depending on what you want to do you might need more or less additional code.
Logged
GPG Fingerprint: B020 D1C1 F289 3B2C 3577  9EAD 455D D175 5913 C7F1

chesslover

  • Jr. Member
  • **
  • Karma: +1/-0
  • Offline Offline
  • Posts: 60
    • View Profile
Re: [Nxt Programming / API] Using AMs to trigger actions or services
« Reply #9 on: October 31, 2017, 03:43:46 am »

Thanks @VanBreuk, again for putting in as much details as possible, it makes things clearer. I think the best solution would be to use a combination of reactive + phased transactions. It will also be interesting to make this as a plugin.
Logged
The Chess Machine: José Raúl Capablanca
 

elective-stereophonic
elective-stereophonic
assembly
assembly