Raw Transaction
Learn how to create raw EVM transactions using the Okto SDK.
The ExecuteEvmRawTransaction()
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





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
// EVM Transaction
EVMTransaction evmTx = new EVMTransaction
{
from = "0x1234...",
to = "0x5678...",
data = "0x...", // contract call data
value = "0" // amount of tokens, usually 0 for read operations
};
ExecuteRawTransaction txData = new ExecuteRawTransaction
{
network_name = "ETHEREUM",
transaction = evmTx
};
try
{
var result = await OktoProviderSDK.Instance.executeRawTransactionPol(txData);
Debug.Log("Transaction submitted, Job ID: " + result.jobId);
var status = await OktoProviderSDK.Instance.ExecuteRawTransactionWithJobStatus(txData);
Debug.Log($"Transaction status: {status.status}");
}
catch (Exception e)
{
Debug.LogError($"Transaction failed: {e.Message}");
}
public async Task<string> ExecuteEvmRawTransaction(string network, string sender, string receipent, string value, string data)
{
string hexValue = string.Empty;
try
{
hexValue = string.IsNullOrEmpty(value) ? "0x" : ToHex(value);
}
catch (Exception ex)
{
return "Invalid Amount!";
}
var transaction = unityCallDataEncoder.CreateTransaction(
from: sender,
to: receipent,
data: string.IsNullOrEmpty(data) ? "0x" : data,
value: hexValue
);
userOp = await CreateUserOp(transaction);
string userOpStr = JsonConvert.SerializeObject(userOp, Formatting.Indented);
Debug.Log($"UserOp created: {JsonConvert.SerializeObject(userOp, Formatting.Indented)}");
userOp = SignUserOp(userOp, network);
userOpStr = JsonConvert.SerializeObject(userOp, Formatting.Indented);
Debug.Log($"UserOp Signed: {JsonConvert.SerializeObject(userOp, Formatting.Indented)}");
JsonRpcResponse<ExecuteResult> txHash = await ExecuteUserOp(userOp);
string txHashStr = JsonConvert.SerializeObject(txHash, Formatting.Indented);
Debug.Log($"Transaction executed. Hash: {txHashStr}");
//clear all inputfield
OnClose();
return txHashStr;
}
Note
For error handling:
- Use the error code to debug issues. Check out the SDK errors and warnings documentation
- For help, navigate to the troubleshooting guide to contact support
Method Overview
Method | Description |
---|---|
string ExecuteEvmRawTransaction | Create 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.
UserOp CreateUserOp(data: Transaction)
creates a user operation for raw EVM transactions.
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
data | RawTransactionIntentParams | Parameters for the raw transaction | Yes |
Where RawTransactionIntentParams
contains:
Field | Type | Description | Required |
---|---|---|---|
caip2Id | string | The network identifier (e.g., eip155:1 for Ethereum) | Yes |
transaction | Transaction | The raw transaction parameters | Yes |
And Transaction
contains:
Field | Type | Description | Required |
---|---|---|---|
from | string | The sender's address | Yes |
to | string | The recipient's address | Yes |
data | string | The transaction data | No |
value | string | The amount of native currency to send | Yes |
Response
Success Response
Field Name | Type | Description |
---|---|---|
result | string | Returns the jobId for the raw transaction |
Success Response
Field Name | Type | Description |
---|---|---|
result | Task<UserOp> | Returns the jobId for the raw transaction |