Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding low-level way to make XCC #2199

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 48 additions & 11 deletions docs/2.build/2.smart-contracts/anatomy/crosscontract.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ While making your contract, it is likely that you will want to query information

<Language value="rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-simple-rs/src/lib.rs"
start="22" end="51" />
<Github fname="external.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-simple-rs/src/external.rs"
start="2" end="12" />
url="https://github.com/near-examples/cross-contract-calls/blob/high-low-level-examples/contract-simple-rs/src/lib.rs"
start="1" end="29" />
<Github fname="external_contract.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/high-low-level-examples/contract-simple-rs/src/external_contract.rs"
start="1" end="8" />
<Github fname="high_level.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/high-low-level-examples/contract-simple-rs/src/high_level.rs"
start="8" end="37" />
<Github fname="low_level.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/high-low-level-examples/contract-simple-rs/src/low_level.rs"
start="7" end="39" />

</Language>

Expand All @@ -64,11 +70,17 @@ Calling another contract passing information is also a common scenario. Below yo

<Language value="rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-simple-rs/src/lib.rs"
start="53" end="80" />
<Github fname="external.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-simple-rs/src/external.rs"
start="2" end="12" />
url="https://github.com/near-examples/cross-contract-calls/blob/high-low-level-examples/contract-simple-rs/src/lib.rs"
start="1" end="29" />
<Github fname="external_contract.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/high-low-level-examples/contract-simple-rs/src/external_contract.rs"
start="1" end="8" />
<Github fname="high_level.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/high-low-level-examples/contract-simple-rs/src/high_level.rs"
start="39" end="66" />
<Github fname="low_level.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/high-low-level-examples/contract-simple-rs/src/low_level.rs"
start="41" end="74" />

</Language>

Expand Down Expand Up @@ -117,7 +129,7 @@ To create a cross-contract call with a callback, create two promises and use the
</TabItem>
<TabItem value="rs" label="🦀 Rust">

There is a helper macro that allows you to make cross-contract calls with the syntax `#[ext_contract(...)]`. It 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`.
There is a helper macro that allows you to make cross-contract calls with the syntax `#[ext_contract(...)]`. It 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`. *That's the high-level way to make cross-contract calls.*

```rust
#[ext_contract(external_trait)]
Expand All @@ -139,6 +151,31 @@ To create a cross-contract call with a callback, create two promises and use the

```

<hr class="subsection" />

There is another way to achieve the same result. You can create a new `Promise` without using a helper macro. *It's the low-level way to make cross-contract calls.*

```rust
let arguments = json!({ "foo": "bar" })
.to_string()
.into_bytes();

let promise = Promise::new("external_address").function_call(
"function_name".to_owned(),
arguments,
DEPOSIT,
GAS
);

promise.then(
// Create a promise to callback query_greeting_callback
Self::ext(env::current_account_id())
.with_static_gas(GAS)
.callback_name(),
);

```

<details>
<summary> Gas </summary>

Expand Down
Loading