Version: ic-cdk=0.9.2
citation path:use ic_cdk::api::management_canister::http_request::http_request;
The http_request method also needs to carry cycles when initiating a request
What is the calculation logic of this cycles? Is there a corresponding example? I am in examples
Checked the similar but hard-coded, how to perform dynamic calculation
My error message is
The http_request resulted into error. RejectionCode: CanisterReject, Error: http_request request sent with 60_106_800 cycles, but 60_148_400 cycles are required.
How to calculate the required cycles in the canister is currently an unsolved problem that we’re aware of. If you’re ok hard-coding some values, you can find the formula here. Some of the numbers in there are outdated. I’ll fix these. But this table contains the current live values
@Severin is there an update on this? I wanna use a http_request as a workaround for the lack of support of the ic_cdk for my use case, but now I come across this issue. This doesnt really help my project and pretty much means I cant continue untill one of the two issues I am having is solved…
using call_raw, fetching the Candid from an unknown canister (canister is defined by the user, not me) and mapping the interface/types to have a correct response instead of this
You could try to fetch the candid:service metadata of the canister and then figure out how to map that to the responses. The IC does not support fetching that on-chain, so you would have to use an http_request for that as well.
IIUC this does something different under the hood, actually. Turning the numbers into words is not possible, but this does the opposite since it would know the field names somehow already.
Not really something I can help. You have to probably just assume the max cost and hope you get a refund
I meat the same issue 2024. maybe i didnt calcute right.
(
"The http_request resulted into error. RejectionCode:
CanisterReject, Error: http_request request sent with
176_928_000 cycles,
but 20_933_203_200 cycles are required.",
)
its about 120times bigger cycles than i expect.
//https://internetcomputer.org/docs/current/developer-docs/gas-cost
pub fn calculate_cost(
node_num: u32,
send_bytes: u64,
receive_bytes: u64,
) -> u128 {
let base_fee =
(3_000_000 + 60_000 * node_num as u64) as u128 * node_num as u128;
let request_cost = 400 * node_num as u64 as u128 * send_bytes as u128;
let response_cost = 800 * node_num as u64 as u128 * receive_bytes as u128;
base_fee + request_cost + response_cost
}
Can i just send with 1T cycles and after http_request it return rest of cycles for me ?