Attribute Macro ext_contract

Source
#[ext_contract]
Expand description

ext_contract takes a Rust Trait and converts it to a module with static methods. Each of these static methods takes positional arguments defined by the Trait, then the receiver_id, the attached deposit and the amount of gas and returns a new Promise.

§Examples

use near_sdk::ext_contract;

#[ext_contract(ext_calculator)]
trait Calculator {
    fn mult(&self, a: u64, b: u64) -> u128;
    fn sum(&self, a: u128, b: u128) -> u128;
}

#[near]
impl Contract {
   pub fn multiply_by_five(&mut self, number: u64) -> Promise {
       ext_calculator::ext(self.calculator_account.clone())
           .with_static_gas(Gas::from_tgas(5))
           .mult(number, 5)
   }
}

See more information about role of ext_contract in NEAR documentation