Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: sui docs #39

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: Sui chain support for sending transactions
sidebar_position: 6
---

For Sui, only the signing and sending trasaction will be different.


```jsx
import { TransactionBlock } from "@mysten/sui.js/transactions";
import { getFullnodeUrl, SuiClient } from "@mysten/sui/client";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { ethers } from "ethers";

const main = async () => {

// configure your private_key
const signer = Ed25519Keypair.fromSecretKey(
Uint8Array.from(
ethers.getBytes(
private_key.startsWith("0x") ? private_key : `0x${private_key}`
)
)
);

// wallet address can be derived if required
// const wallet = signer.getPublicKey().toSuiAddress();

// get transaction data same as evm
const txResponse = await getTransaction(quoteData); // quoteData has been fetched in step 1

// create sui client
const rpcUrl = getFullnodeUrl("mainnet");
const client = new SuiClient({ url: rpcUrl });

// sending the transaction using the data given by the pathfinder
const byteArray = hexToUint8Array(txResponse.data); // convert api tnx hex data to tnx byte array
const transactionBlock = TransactionBlock.from(byteArray);
const result = await signAndSendTx(client, transactionBlock, signer)

console.log(`txHash ${result.digest}`);
}

async function signAndSendTx(
client,
txb,
signer
) {
return await client.signAndExecuteTransaction({
transaction: txb,
signer,
requestType: "WaitForLocalExecution",
options: {
showEffects: true,
showEvents: true,
showRawInput: true,
showInput: true,
showBalanceChanges: true,
showObjectChanges: true,
},
});
}

main()
```