-
Notifications
You must be signed in to change notification settings - Fork 2
/
broadcast.js
32 lines (26 loc) · 930 Bytes
/
broadcast.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {
generateEndpointBroadcast,
generatePostBodyBroadcast,
BroadcastMode,
} from '@gravity-bridge/provider'
import { nodeurl } from '../constants/nodeConstants'
export async function BroadcastEIP712Tx(signedTx, optionalEndpoint) {
const postOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: generatePostBodyBroadcast(signedTx, BroadcastMode.Block),
}
var broadcastEndpoint;
if (optionalEndpoint !== undefined) {
broadcastEndpoint = `${optionalEndpoint}${generateEndpointBroadcast()}`
} else {
broadcastEndpoint = `${nodeurl}${generateEndpointBroadcast()}`
}
const broadcastPost = await fetch(
broadcastEndpoint,
postOptions,
)
console.log("Broadcasting to ", broadcastEndpoint)
console.log("Broadcasting Tx: ", JSON.stringify(postOptions))
return await broadcastPost.json()
}