Skip to content

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);
FieldTypeRequiredDescription
to0x${string}YesThe recipient address.
valuestringYesAmount in wei as a string. Pass "0" for contract interactions.
data0x${string}NoEncoded call data. Omit for plain ETH transfers.
chainIdnumberNoThe chain ID to include in the signature.
noncenumberNoTransaction nonce.
gasnumberNoGas limit.
gasPricenumberNoGas price in wei.
maxFeePerGasnumberNoFor EIP-1559 transactions.
maxPriorityFeePerGasnumberNoFor EIP-1559 transactions.
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
}

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,
});
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
}
}