Macro near_sdk_sim::deploy[][src]

macro_rules! deploy {
    ($contract: ident, $account_id:expr, $wasm_bytes: expr, $user:expr) => { ... };
    ($contract: ident, $account_id:expr, $wasm_bytes: expr, $user:expr, $deposit: expr) => { ... };
    ($contract: ident, $account_id:expr, $wasm_bytes: expr, $user_id:expr, $deposit:expr, $gas:expr, $method: ident, $($arg:expr),* ) => { ... };
    (contract: $contract: ident, contract_id: $account_id:expr, bytes: $wasm_bytes: expr, signer_account: $user:expr) => { ... };
    (contract: $contract: ident, contract_id: $account_id:expr, bytes: $wasm_bytes: expr, signer_account: $user:expr, deposit: $deposit: expr) => { ... };
    (contract: $contract: ident, contract_id: $account_id:expr, bytes: $wasm_bytes: expr, signer_account: $user:expr, deposit: $deposit: expr, gas: $gas:expr, init_method: $method: ident($($arg:expr),*) ) => { ... };
    (contract: $contract: ident, contract_id: $account_id:expr, bytes: $wasm_bytes: expr, signer_account: $user:expr, gas: $gas:expr, init_method: $method: ident($($arg:expr),*) ) => { ... };
    (contract: $contract: ident, contract_id: $account_id:expr, bytes: $wasm_bytes: expr, signer_account: $user:expr, deposit: $deposit: expr, init_method: $method: ident($($arg:expr),*) ) => { ... };
    (contract: $contract: ident, contract_id: $account_id:expr, bytes: $wasm_bytes: expr, signer_account: $user:expr, init_method: $method: ident($($arg:expr),*) ) => { ... };
}

Deploys a contract. Will either deploy or deploy and initialize a contract. Returns a ContractAccount<T> where T is the first argument.

Examples

The simplest example is deploying a contract without initializing it.

This example deploys and initializes the contract.

use near_sdk_sim::*;
use fungible_token::ContractContract;
use std::convert::TryInto;
use near_sdk::json_types::ValidAccountId;
let master_account = near_sdk_sim::init_simulator(None);
let master_account_id: ValidAccountId = master_account.account_id().try_into().unwrap();
let initial_balance = near_sdk_sim::to_yocto("35");
let contract = deploy! {
  contract: ContractContract,
  contract_id: "contract",
  bytes: &TOKEN_WASM_BYTES,
  signer_account: master_account,
  init_method: new_default_meta(master_account_id, initial_balance.into())
};

This example used the default values for the initial deposit to the new contract’s account and gas for the contract call. So it is the same as:

use fungible_token::ContractContract;
use std::convert::TryInto;
use near_sdk_sim::*;
use near_sdk::json_types::ValidAccountId;
let master_account = near_sdk_sim::init_simulator(None);
let master_account_id: ValidAccountId = master_account.account_id().try_into().unwrap();
let initial_balance = near_sdk_sim::to_yocto("35");
let contract = deploy! {
contract: ContractContract,
  contract_id: "contract",
  bytes: &TOKEN_WASM_BYTES,
  signer_account: master_account,
  deposit: near_sdk_sim::STORAGE_AMOUNT, // Deposit required to cover contract storage.
  gas: near_sdk_sim::DEFAULT_GAS,
  init_method: new_default_meta(master_account_id, initial_balance.into())
};