Developer guide / Building DApps
Session Transactions
Send transactions from a seed in a single RPC call without signing them.
With session transactions, you send a transaction to Somnia in one RPC call. Signing, nonce management, and gas pricing are handled for you. You can also submit many transactions in parallel and have them execute quickly.
You provide a 32-byte seed and the transaction fields (recipient, value, calldata and gas limit). The node handles the rest. It derives the account's key from the seed, sets the nonce and gas price, signs and submits the transaction, retries transient errors, and returns the receipt once the transaction has executed.
They were added in the Ingot hard fork and use two methods:
somnia_getSessionAddressreturns the address a seed controls.somnia_sendSessionTransactionsends a transaction from that address and returns its receipt.
Note
Session transactions are not related to the session keys of Somnia Accounts.
Quickstart
The examples use Somnia Testnet at https://api.infra.testnet.somnia.network. Get test STT from the faucet first.
1. Generate a seed
Use 32 random bytes for the seed.
openssl rand -hex 32
8f3a9c2e5b7d4f1a6c0e9b8d7a5f3e2c1b0a9d8e7f6c5b4a3928170615f4e3d2
2. Get the session address
curl -s -X POST https://api.infra.testnet.somnia.network \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"somnia_getSessionAddress","params":["0x8f3a9c2e5b7d4f1a6c0e9b8d7a5f3e2c1b0a9d8e7f6c5b4a3928170615f4e3d2"],"id":1}'
{"jsonrpc":"2.0","id":1,"result":"0xeb0d7515becd17b626c4dcfb9cdf09be0c567668"}
3. Fund the session account
The session account pays its own gas, so send it some STT from any wallet before you use it.
cast send 0xeb0d7515becd17b626c4dcfb9cdf09be0c567668 --value 1ether --private-key <private_key> --rpc-url https://api.infra.testnet.somnia.network
4. Send a transaction
A plain transfer of 0.001 STT (0x38d7ea4c68000 wei).
curl -s -X POST https://api.infra.testnet.somnia.network \
-H "Content-Type: application/json" \
-d '{
"jsonrpc":"2.0",
"method":"somnia_sendSessionTransaction",
"params":[{
"seed": "0x8f3a9c2e5b7d4f1a6c0e9b8d7a5f3e2c1b0a9d8e7f6c5b4a3928170615f4e3d2",
"gas": "0x5208",
"to": "0x1909cdb9524d065e5751d2fe79e2b9ad54d822e6",
"value": "0x38d7ea4c68000"
}],
"id":1
}'
The call returns once the transaction has executed, with the same receipt object as eth_getTransactionReceipt.
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"transactionHash": "0x4c1e2a7f9b3d8e6a0f5c2b1d9e8a7f6c3b2a1d0e9f8c7b6a5d4e3f2a1b0c9d8e",
"blockNumber": "0x1a2b3c4",
"from": "0xeb0d7515becd17b626c4dcfb9cdf09be0c567668",
"to": "0x1909cdb9524d065e5751d2fe79e2b9ad54d822e6",
"status": "0x1",
"gasUsed": "0x5208",
"logs": []
}
}
Parameters
somnia_sendSessionTransaction takes one object:
| Field | Type | Required | Description |
|---|---|---|---|
seed |
bytes32 |
yes | Identifies the session and its account |
gas |
uint64 |
yes | Gas limit for the transaction, as hex |
to |
address |
no | Recipient. Leave it out to deploy a contract |
value |
uint256 |
no | Amount of native token to send, in wei. Default 0 |
data |
bytes |
no | ABI-encoded calldata, or contract init code |
You don't pass a nonce, gas price or signature: the node fills them in.
Considerations
- Transient errors are retried automatically. These include a full mempool, a stale nonce, or a failed submission. Other errors are returned to the caller.
- A timeout doesn't mean the transaction failed. If no receipt arrives within the node's timeout (30 seconds by default), the call returns a
timeouterror. The transaction may still be in the mempool, and can later execute or be dropped. - Nonce gaps are filled with no-ops. The node assigns nonces as it accepts transactions, so several can be pending at once. If one fails with a non-retryable error or times out, the node sends a no-op with the same nonce so later transactions aren't blocked. The no-op is a zero-value transfer to the zero address with a 21,000 gas limit, paid by the session account. The call still returns the original error.
- If the failed transaction had the latest nonce, the node reuses that nonce and sends no no-op.
- If the no-op fails, for example because the account can't pay for it, the node cancels all pending transactions for the session.
- Pending transactions are stored on the node. Each session's pending queue is held in memory on the node you call, so a restart loses queued transactions. The account itself is onchain and works with any node.
- Treat seeds like private keys. Generate them from a cryptographically secure random source and store them securely.
- Only send seeds to nodes you trust, over HTTPS. The node that receives a seed can sign for the account.
- Keep the balance low. Any node that receives the seed can sign for the account, so fund it with only what it needs.