Amiya Behera
Amiya Behera

Reputation: 2270

Explanation for near sdk promise

https://docs.rs/near-sdk/0.11.0/near_sdk/struct.Promise.html

In cross contract call example

It contains following promise

impl CrossContract {
    pub fn deploy_status_message(&self, account_id: String, amount: u64) {
        Promise::new(account_id)
            .create_account()
            .transfer(amount as u128)
            .add_full_access_key(env::signer_account_pk())
            .deploy_contract(
                include_bytes!("../status-message-contract/status_message.wasm").to_vec(),
            );
    }

This is the near command for calling deploy_status_message

near call cross_contract deploy_status_message '{"account_id": "status_message", "amount":1000000000000000}' --accountId mainaccount

Can you please explain this Promise chain:

1) It takes argument status_message as account_id, create_account should create an account status_message, but

near state status_message

gives error

account status_message does not exist while viewing

2) Also what should

include_bytes!(...) 

contain, which string?

3) What transfer function do here? Does it takes 1000000000000000 from mainaccount and deposit it in status_message account?

4) add_full_access_key Adds full access key to the which account? status_message? What is the need for env::signer_account_pk() as argument?

Upvotes: 0

Views: 497

Answers (1)

berryguy
berryguy

Reputation: 1154

1 It does. You probably have the wrong env var and therefore end up querying a different network. UPD: The example is broken. Fix here https://github.com/near/near-sdk-rs/pull/193.

2 include_bytes is a built-in rust macro that is not related to near-sdk-rs. See https://doc.rust-lang.org/beta/std/macro.include_bytes.html

3 Not sure what is mainaccount, but it transfers 1000000000000000 from the current account balance of the contract account to the status_message account. Note that the current account balance includes the attached deposit as well.

4 Yes it adds to the status_message account. To add a key you need to specify the key that you are adding and env::signer_account_pk() gives you a key.

Upvotes: 1

Related Questions