pub struct FunctionCall { /* private fields */ }Expand description
A standalone function call configuration, decoupled from any transaction.
Use this when you need to pre-build calls and compose them into a transaction later. This is especially useful for dynamic transaction composition (e.g. in a loop) or for batching typed contract calls into a single transaction.
Note: FunctionCall does not capture a receiver/contract account. The call
will execute against whichever receiver_id is set on the transaction it’s
added to.
§Examples
// Pre-build calls independently
let init = FunctionCall::new("init")
.args(serde_json::json!({"owner": "alice.testnet"}))
.gas(Gas::from_tgas(50));
let notify = FunctionCall::new("notify")
.args(serde_json::json!({"msg": "done"}));
// Compose into a single atomic transaction
near.transaction("contract.testnet")
.add_action(init)
.add_action(notify)
.send()
.await?;// Dynamic composition in a loop
let calls = vec![
FunctionCall::new("method_a").args(serde_json::json!({"x": 1})),
FunctionCall::new("method_b").args(serde_json::json!({"y": 2})),
];
let mut tx = near.transaction("contract.testnet");
for call in calls {
tx = tx.add_action(call);
}
tx.send().await?;Implementations§
Source§impl FunctionCall
impl FunctionCall
Sourcepub fn new(method: impl Into<String>) -> Self
pub fn new(method: impl Into<String>) -> Self
Create a new function call for the given method name.
Sourcepub fn args_borsh(self, args: impl BorshSerialize) -> Self
pub fn args_borsh(self, args: impl BorshSerialize) -> Self
Set Borsh-encoded arguments.
Sourcepub fn deposit(self, amount: impl IntoNearToken) -> Self
pub fn deposit(self, amount: impl IntoNearToken) -> Self
Trait Implementations§
Source§impl Debug for FunctionCall
impl Debug for FunctionCall
Source§impl From<FunctionCall> for Action
impl From<FunctionCall> for Action
Source§fn from(call: FunctionCall) -> Self
fn from(call: FunctionCall) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for FunctionCall
impl RefUnwindSafe for FunctionCall
impl Send for FunctionCall
impl Sync for FunctionCall
impl Unpin for FunctionCall
impl UnsafeUnpin for FunctionCall
impl UnwindSafe for FunctionCall
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more