File tree 2 files changed +7
-6
lines changed
2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -45,14 +45,12 @@ await sub.unsubscribe();
45
45
### Socket.io
46
46
47
47
``` js
48
- import { io } from " socket.io-client" ;
49
- import * as stacks from ' @stacks/blockchain-api-client' ;
48
+ import { StacksApiSocketClient } from ' @stacks/blockchain-api-client' ;
50
49
51
- // for testnet, replace with https://api.testnet.hiro.so/
52
- const socketUrl = " https://api.mainnet.hiro.so/ " ;
50
+ // for testnet, replace with https://api.testnet.hiro.so
51
+ const socketUrl = " https://api.mainnet.hiro.so" ;
53
52
54
- const socket = io (socketUrl);
55
- const sc = new stacks.StacksApiSocketClient (socket);
53
+ const sc = new StacksApiSocketClient ({ url: socketUrl });
56
54
57
55
sc .subscribeAddressTransactions (' ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA' , (address , tx ) => {
58
56
console .log (' address:' , address);
Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ function createStacksApiSocket(opts?: StacksApiSocketConnectionOptions) {
46
46
subscriptions : Array . from ( new Set ( opts ?. subscriptions ) ) . join ( ',' ) ,
47
47
} ,
48
48
} ;
49
+ if ( ! socketOpts . transports ) {
50
+ socketOpts . transports = [ 'websocket' ] ;
51
+ }
49
52
const socket : StacksApiSocket = io ( getWsUrl ( opts ?. url ?? BASE_PATH ) . href , socketOpts ) ;
50
53
return socket ;
51
54
}
You can’t perform that action at this time.
0 commit comments