mirror of
https://github.com/eosswedenorg/thalos-docs
synced 2026-06-16 04:34:55 +02:00
docs/api/examples.md: Adding nodejs example.
This commit is contained in:
parent
c0b17d8d02
commit
abcff7a8e0
1 changed files with 50 additions and 1 deletions
|
|
@ -65,6 +65,55 @@ func main() {
|
|||
|
||||
```
|
||||
|
||||
## Nodejs
|
||||
|
||||
install the thalos client library:
|
||||
|
||||
`npm install -D thalos-nodejs`
|
||||
|
||||
::: code-group
|
||||
|
||||
```ts [TypeScript]
|
||||
import * as thalos from 'thalos-nodejs';
|
||||
|
||||
// Create client.
|
||||
const client = thalos.createRedisClient({
|
||||
// url: "redis://localhost:6379",
|
||||
// prefix: "ship",
|
||||
ns: "1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4" // wax mainnet
|
||||
})
|
||||
|
||||
client.onAction({contract: "atomicassets", name: "logtransfer"}, (action:thalos.ActionTrace) => {
|
||||
console.log("Transfer", "From/To:", action.data['from'], "->", action.data['to'], "Assets:", action.data['asset_ids'], action.data['memo']);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
```js [JavaScript]
|
||||
|
||||
const thalos = require('thalos-nodejs');
|
||||
|
||||
// Create client.
|
||||
const client = thalos.createRedisClient({
|
||||
// url: "redis://localhost:6379",
|
||||
// prefix: "ship",
|
||||
ns: "1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4" // wax mainnet
|
||||
})
|
||||
|
||||
client.onAction({contract: "atomicassets", name: "logtransfer"}, action => {
|
||||
console.log("Transfer", "From/To:", action.data['from'], "->", action.data['to'], "Assets:", action.data['asset_ids'], action.data['memo']);
|
||||
});
|
||||
|
||||
```
|
||||
:::
|
||||
|
||||
```
|
||||
Transfer From/To: dtknw.c.wam -> farmersworld Assets: [ '1099900831604' ] feed_animal:1099885261718
|
||||
Transfer From/To: atomicmarket -> xk5qu.wam Assets: [ '1099519946844' ] AtomicMarket Cancelled Auction - ID # 1238572
|
||||
Transfer From/To: xk5qu.wam -> atomicmarket Assets: [ '1099519946844' ] auction
|
||||
Transfer From/To: ponyslaystat -> wombatmaster Assets: [ '1099880264627' ]
|
||||
```
|
||||
|
||||
## Python
|
||||
|
||||
This example will listen for new atomicasset transfers and print them to standard output.
|
||||
|
|
@ -108,4 +157,4 @@ Transfer From/To: agy2a.c.wam -> w4mwy.wam Assets: ['1099546474727', '1099515237
|
|||
Transfer From/To: fzzm..c.wam -> lstm4.c.wam Assets: ['1099535666180', '1099514473189', '1099524729561']
|
||||
Transfer From/To: 2ahmc.c.wam -> mmklu.c.wam Assets: ['1099538558402', '1099514074361', '1099514699356']
|
||||
Transfer From/To: atomicmarket -> xk5qu.wam Assets: ['1099541038508'] AtomicMarket Cancelled Auction - ID # 1238125
|
||||
```
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue