Function promise_result

Source
pub fn promise_result(result_idx: u64) -> PromiseResult
Expand description

If the current function is invoked by a callback we can access the execution results of the promises that caused the callback.

ยงExamples

use near_sdk::env::{promise_result, promise_results_count, log_str};
use near_sdk::PromiseResult;

assert!(promise_results_count() > 0);

// The promise_index will be in the range [0, n)
// where n is the number of promises triggering this callback,
// retrieved from promise_results_count()
let promise_index = 0;
let result = promise_result(promise_index);

match result {
    PromiseResult::Successful(data) => {
        log_str(format!("Result as Vec<u8>: {:?}", data).as_str());
    }
    PromiseResult::Failed => {
        log_str("Promise failed!");
    }
};

More low-level info here: near_vm_runner::logic::VMLogic::promise_result Example usages: one, two, three, four