Skip to content

Commit

Permalink
Update sui-support.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalroute authored Oct 29, 2024
1 parent c2c9471 commit a517d66
Showing 1 changed file with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ 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
Expand All @@ -20,12 +34,32 @@ const main = async () => {
const client = new SuiClient({ url: rpcUrl });

// sending the transaction using the data given by the pathfinder
const byteArray = hexToUint8Array(txResponse.data);
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, walletAddress)
const result = await signAndSendTx(client, transactionBlock, signer)

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

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

main()
```
```

0 comments on commit a517d66

Please sign in to comment.