Sign a Transaction
signTransaction() opens the widget and shows the user an “Approve Transaction” screen. When approved, the widget sends the transaction to KMS for signing and returns the raw signed transaction.
This is a lower-level operation. If you’re using OxGasClient, transaction signing happens internally when you call sendTransaction() — you don’t need to call signTransaction() yourself.
const result = await auth.signTransaction({ to: '0xRecipientAddress', value: '10000000000000000', // 0.01 ETH in wei data: '0x', chainId: 11155111, nonce: 5,});
console.log('Raw signed tx:', result.rawTx);console.log('Tx hash:', result.txHash);Parameters
Section titled “Parameters”| Field | Type | Required | Description |
|---|---|---|---|
to | 0x${string} | Yes | The recipient address. |
value | string | Yes | Amount in wei as a string. Pass "0" for contract interactions. |
data | 0x${string} | No | Encoded call data. Omit for plain ETH transfers. |
chainId | number | No | The chain ID to include in the signature. |
nonce | number | No | Transaction nonce. |
gas | number | No | Gas limit. |
gasPrice | number | No | Gas price in wei. |
maxFeePerGas | number | No | For EIP-1559 transactions. |
maxPriorityFeePerGas | number | No | For EIP-1559 transactions. |
Return value
Section titled “Return value”interface SignTxResult { rawTx: `0x${string}`; // The raw signed transaction, ready to broadcast txHash: `0x${string}`; // The transaction hash from: `0x${string}`; // The signer's address}Broadcasting the transaction
Section titled “Broadcasting the transaction”signTransaction() signs but does not broadcast. Use a library like viem or ethers to send the raw transaction:
import { createPublicClient, http } from 'viem';import { sepolia } from 'viem/chains';
const publicClient = createPublicClient({ chain: sepolia, transport: http(),});
const result = await auth.signTransaction({ to: '0xRecipient', value: '0', chainId: 11155111,});
const hash = await publicClient.sendRawTransaction({ serializedTransaction: result.rawTx,});Error handling
Section titled “Error handling”import { SigningRejectedError, SigningTimeoutError, NotConnectedError } from '0xgas-auth';
try { const result = await auth.signTransaction({ to: '0x...', value: '0' });} catch (err) { if (err instanceof NotConnectedError) { // User not logged in — call login() first } else if (err instanceof SigningRejectedError) { // User clicked "Reject" in the widget } else if (err instanceof SigningTimeoutError) { // Widget was left open too long without a response }}