1

I am looking for an example of checking transactions that occur on my account. I read that there is a demuxjs library that supports this, but it is difficult to approach.

Clarification: I am building a trading platform. When a user orders a Buy token, they will have to send EOS to my EOS account. The part I'm building is getting that order information via EOS account and adding it to the database.

Update: I did it with demuxjs but it was slow, When I push the contract to send EOS until the demuxjs receive info 50 seconds->3 minutes in Jungle and Mainnet, Is there any way to speed up demux watch action faster?

3
  • you want to know all your transaction through or in your account ? Commented Feb 1, 2019 at 12:14
  • I am building a trading platform, when a user orders an Buy token, they will have to send EOS to my EOS account, The part I'm building is getting that order information via eos account and adding it to the database
    – Son Le
    Commented Feb 1, 2019 at 16:25
  • bloks.io/transaction/… For example, I want to receive information about this transaction immediately and automatically add to database
    – Son Le
    Commented Feb 1, 2019 at 16:27

2 Answers 2

3

If you have the cheddar, you could go for a web-socket connection.

https://www.dfuse.io/en - EOS Canada

https://eospark.com/openapi


If not, demux is likely your best bet. For best results, you would want to host your own node or use an API endpoint that shares your need for consistent up time.

Demux isn't too difficult to implement and there are many examples out there. Basically in your app.js you specify an API endpoint that you would like to ping (the default interval is 250ms or 2 times each block).

Here's my app.js: https://github.com/NatPDeveloper/eos-chess/blob/master/app.js#L35

// DEMUX ACTION READER SETUP
const { NodeosActionReader } = require("demux-eos")
const MyActionHandler = require("./js/lib/demux-js/ActionHandler")
const { BaseActionWatcher } = require("demux")
const updaters = require("./js/lib/demux-js/updaters")
const effects = require("./js/lib/demux-js/effects") 

// LOCAL
// const actionReader = new NodeosActionReader(
//     "http://127.0.0.1:8888", // Locally hosted node needed for reasonable indexing speed
//     179000, // First actions relevant to this dapp happen at this block
// )

// JUNGLE TESTNET
const actionReader = new NodeosActionReader(
    "https://jungle.eosn.io:443", // Locally hosted node needed for reasonable indexing speed
    1196555, // First actions relevant to this dapp happens at this block
)

const actionHandler = new MyActionHandler(
    updaters,
    effects,
)

const actionWatcher = new BaseActionWatcher(
    actionReader,
    actionHandler,
    250, // Poll at twice the block interval for less latency
)

actionWatcher.watch() // Start watch loop

From there you can specify in the updaters/effects js files which contract_name:action_name you want to listen for. Upon demux picking one of those off the chain, you can pull the block data then CRUD your DB of choice. MonsterEOS uses this as does my chess-eos dapp.

demux-js: https://github.com/EOSIO/demux-js

code example (updaters/effects): https://github.com/NatPDeveloper/eos-chess/tree/master/js/lib/demux-js

block one code example: https://github.com/EOSIO/demux-js/tree/develop/examples/eos-transfers

block one simple blog example: https://github.com/EOSIO/eosio-project-demux-example


If you get stuck, hit up the EOS Developers channel. There are some great people in there who will help: https://t.me/joinchat/Esi1OkPktgcFeJ3Lmlcrqg

2
  • Thank you. In the example github.com/EOSIO/demux-js/tree/develop/examples/eos-transfers I also tried to replace the actionType: "eosio.token :: transfer" code into my account to track it but it didn't work.
    – Son Le
    Commented Feb 5, 2019 at 2:21
  • in actionType ,How do I change it to track my account? As in your example, you are watching 1 contract, and I am a watch account
    – Son Le
    Commented Feb 5, 2019 at 7:13
1

Like @Nat said you should use one of the provided Websocket-APIs.

https://www.dfuse.io/en

https://eospark.com/openapi

Dfuse runs very stable and very fast and it seems a lot more reliable. There are several Client-Libs available.

here https://github.com/dfuse-io and here https://github.com/cmadh/EosWsSharp

3
  • thank @Morvling,I watched, but I don't know how much it will cost.
    – Son Le
    Commented Feb 8, 2019 at 9:46
  • Havn't used eospark myself so I don't know the price. Dfuse is free too use, with some limitations if you only have one of the basic keys. There's a button on the Top-Right on dfuse.io/en where you can request your free key. The resources available to you are very generous, you probably don't need a different key. If you need one of the extended keys, you have to ask EOS Canada.
    – cmadh
    Commented Feb 12, 2019 at 14:58
  • thank @cmadh .I have found my solution. I thought of writing plugins run on my eosnode.
    – Son Le
    Commented Feb 14, 2019 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.