Intents

Raw Transaction

Learn how to create raw EVM transactions using the Okto SDK.

The evmRawTransaction() function creates a user operation for executing raw EVM transactions. This function allows you to create custom transactions by specifying the raw transaction parameters.

Available on

Ethereum
Ethereum
Polygon
Polygon
Avalanche
Avalanche
Arbitrum
Arbitrum
BSC
BSC
Fantom
Fantom
Linea
Linea
Metis
Metis
Optimism
Optimism
Base
Base
Base Sepolia
Base Sepolia
HyperEVM Testnet
HyperEVM Testnet
Polygon Amoy
Polygon Amoy

To enable these chains for your application, please configure them in the Okto Dashboard.

Not available on

There are two ways to implement raw transactions:

  • Abstracted Flow: A simplified approach where the user operation is automatically created, signed, and executed in a single step. Perfect for most applications.
  • UserOp Flow: A granular approach where you manually control the creation, signing, and execution of the user operation. Useful for custom implementations or advanced use cases.

Example

import { useOkto } from '@okto_web3/react-sdk';
import { evmRawTransaction } from '@okto_web3/react-sdk'; 
 
function RawTransaction() {
    const oktoClient = useOkto(); 
 
    async function handleRawTransaction() {
        try {
            const rawTxParams = { 
                caip2Id: "eip155:1", // Ethereum Mainnet 
                transaction: { 
                    from: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", 
                    to: "0x23581767a106ae21c074b2276D25e5C3e136a68b", 
                    data: "0x", // Optional transaction data 
                    value: BigInt("1000000000000000000") // 1 ETH 
                } 
            }; 
            
            // Execute the transaction
            const jobId = await evmRawTransaction(oktoClient, rawTxParams); 
            console.log('Transaction jobId:', jobId);
        } catch (error) {
            console.error('Error in raw transaction:', error);
        }
    }
 
    return (
        <button onClick={handleRawTransaction}>
            Execute Raw Transaction
        </button>
    );
}

Note

For error handling:

Method Overview

MethodDescription
async evmRawTransactionCreate a user operation for raw EVM transaction

EVM Raw Transaction

Note

Before using this function, ensure your target chain is an EVM-compatible chain by checking the Supported Chains and Tokens documentation.

async evmRawTransaction(oktoClient: OktoClient, data: RawTransactionIntentParams) creates a user operation for raw EVM transactions.

Parameters

ParameterTypeDescriptionRequired
oktoClientOktoClientInstance of OktoClient obtained from useOkto hookYes
dataRawTransactionIntentParamsParameters for the raw transactionYes

Where RawTransactionIntentParams contains:

FieldTypeDescriptionRequired
caip2IdstringThe network identifier (e.g., eip155:1 for Ethereum)Yes
transactionEVMRawTransactionThe raw transaction parametersYes

And EVMRawTransaction contains:

FieldTypeDescriptionRequired
fromAddressThe sender's addressYes
toAddressThe recipient's addressYes
dataHashThe transaction dataNo
valueHashThe amount of native currency to sendYes

Response

Success Response

Field NameTypeDescription
resultPromise<string>Returns the jobId for the raw transaction

On this page