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

Added the README's for cross-contract-calls & factory-contract. #1232

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
88 changes: 85 additions & 3 deletions examples/cross-contract-calls/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,87 @@
# Cross contract
# Cross Contract Call

Example of using cross-contract functions with promises.
Example implementation of a cross-contract call using [near-sdk-rs].

TBD
[near-sdk-rs]: https://github.com/near/near-sdk-rs

NOTES:

- This example demonstrates how to call another contract from within a contract.
- Ensure that the called contract is deployed and accessible.

## Project Structure

- `.cargo`: Configuration files for Cargo, the Rust package manager.
- `high-level/src`: Source code for the high-level cross-contract call example.
- `low-level/src`: Source code for the low-level cross-contract call example.
- `res`: Compiled contract binaries.
- `tests`: Integration tests for the cross-contract call examples.

## Building

To build run:

```bash
./build.sh
```

## Testing

To test run:

```bash
cargo test --package cross-contract-call -- --nocapture
```

## Usage

1. Prerequisites:

- Install cargo-near:

```bash
cargo install cargo-near
```

- Create a new testnet account:

```bash
cargo near create-dev-account
```

2. Deploy the contracts:

- Build and deploy the high-level contract:

```bash
cargo build --target wasm32-unknown-unknown --release
near dev-deploy --wasmFile path/to/high-level-contract.wasm
```

- Build and deploy the low-level contract:

```bash
cargo build --target wasm32-unknown-unknown --release
near dev-deploy --wasmFile path/to/low-level-contract.wasm
```

3. Initiate a cross-contract call:

- Call the high-level contract to initiate a cross-contract call to the low-level contract:

```bash
near call your-high-level-contract-account.testnet calculate_factorial '{"number": 5}' --accountId your-account.testnet
```

NOTE: Replace path/to/high-level-contract.wasm and path/to/low-level-contract.wasm with the actual paths to your compiled WebAssembly files, and your-high-level-contract-account.testnet and your-account.testnet with your actual NEAR testnet account IDs.

## Dependencies

- [near-sdk-rs](https://github.com/near/near-sdk-rs): NEAR Protocol's Rust SDK.
- [Cargo](https://doc.rust-lang.org/cargo/): Rust's package manager.

## Changelog

### `1.0.0`

- Initial implementation of cross-contract call functionality.
91 changes: 89 additions & 2 deletions examples/factory-contract/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,90 @@
# Factory contract
# Factory Contract

TBD
Example implementation of a factory contract using [near-sdk-rs].

[near-sdk-rs]: https://github.com/near/near-sdk-rs

NOTES:

- This example demonstrates how to create and manage multiple instances of a contract from a factory contract.
- Ensure that the factory contract is deployed and accessible.

## Project Structure

- `.cargo`: Configuration files for Cargo, the Rust package manager.
- `high-level/src`: Source code for the high-level factory contract example.
- `low-level/src`: Source code for the low-level factory contract example.
- `res`: Compiled contract binaries.
- `tests`: Integration tests for the factory contract examples.

## Building

To build run:

```bash
./build.sh
```

## Testing

To test run:

```bash
cargo test --package factory-contract -- --nocapture
```

## Usage

## Usage

1. Prerequisite: Install cargo-near:

```bash
cargo install cargo-near
```

2. Create a new testnet account:

```bash
cargo near create-dev-account
```

3. Deploy the factory contract:

```bash
cargo cargo build --target wasm32-unknown-unknown --release
near dev-deploy --wasmFile target/wasm32-unknown-unknown/release/factory_contract.wasm
```

4. Use the factory contract to create instances of the target contract:

```bash
near contract call-function as-transaction your-factory-contract-account.testnet deploy_status_message json-args '{"account_id": "sub.your-factory-contract-account.testnet"}' prepaid-gas '100 Tgas' attached-deposit '0 NEAR'
```

5. Demonstrate calls to simple_call and complex_call functions:

- Call simple_call function:

```bash
near call your-factory-contract-account.testnet simple_call '{"arg1": "value1"}' --accountId your-account.testnet
```

- Call complex_call function:

```bash
near call your-factory-contract-account.testnet complex_call '{"arg1": "value1", "arg2": "value2"}' --accountId your-account.testnet
```

NOTE FOR 3, 4 AND 5: Replace target/wasm32-unknown-unknown/release/factory_contract.wasm with the actual path to your compiled WebAssembly file, and your-factory-contract-account.testnet with your actual NEAR testnet account ID.

## Dependencies
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demonstrate calls to simple_call and complex_call functions.


- [near-sdk-rs](https://github.com/near/near-sdk-rs): NEAR Protocol's Rust SDK.
- [Cargo](https://doc.rust-lang.org/cargo/): Rust's package manager.

## Changelog

### `1.0.0`

- Initial implementation of factory contract functionality.
Loading