Skip to content

Instantly share code, notes, and snippets.

@mgild
Created March 27, 2024 20:56
Show Gist options
  • Save mgild/ddc209ad5ab13daf33d80c4c9dfc9831 to your computer and use it in GitHub Desktop.
Save mgild/ddc209ad5ab13daf33d80c4c9dfc9831 to your computer and use it in GitHub Desktop.
public async sendRestTransaction(
serializedTx: Uint8Array | Buffer | Array<number>,
retries,
rpcEndpoint = this.defaultConnection.rpcEndpoint,
skipPreFlight = true
): Promise<TransactionSignature> {
const res = await fetch(rpcEndpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: Math.round(Math.random() * 1_000_000),
method: "sendTransaction",
params: [
serializedTx!.toString("base64"),
{
skipPreflight: skipPreFlight,
encoding: "base64",
maxRetries: retries,
},
],
}),
});
return ((await res.json()) as any)!.result!;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment