starknet_estimateMessageFee
estimate the L2 fee of a message sent on L1
estimates the resources required by the l1_handler transaction induced by the message
Parameters
Parameter | Type | Description |
---|---|---|
message | object | L1 message object with from_address, to_address, entry_point_selector, and payload |
block_id | string | Block reference ("latest", "l1_accepted", block hash, or block number) |
Request
{
"jsonrpc": "2.0",
"method": "starknet_estimateMessageFee",
"params": [
{
"from_address": "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"to_address": "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"payload": [
"0x1"
],
"entry_point_selector": "0x0102030405"
},
{
"block_hash": "0x05abbad1e5"
}
],
"id": 1
}
Returns
The fee estimation
Fee estimation with L1/L2 gas consumption and prices
Errors
Code | Message |
---|---|
40 | Contract error |
24 | Block not found |
Examples
- cURL
- JavaScript
curl -X POST https://api-starknet-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "starknet_estimateMessageFee",
"params": [
{
"from_address": "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"to_address": "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"payload": [
"0x1"
],
"entry_point_selector": "0x0102030405"
},
{
"block_hash": "0x05abbad1e5"
}
],
"id": 1
}'
import { RpcProvider } from 'starknet';
const provider = new RpcProvider({
nodeUrl: 'https://api-starknet-mainnet.n.dwellir.com/YOUR_API_KEY',
});
const payload = {
method: 'starknet_estimateMessageFee',
params: [
{
"from_address": "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"to_address": "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"payload": [
"0x1"
],
"entry_point_selector": "0x0102030405"
},
{
"block_hash": "0x05abbad1e5"
}
]
};
const result = await provider.fetchEndpoint(payload.method, payload.params);
console.log(result);