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 3 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
86 changes: 83 additions & 3 deletions examples/cross-contract-calls/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,85 @@
# 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 near deploy --wasmFile path/to/high-level-contract.wasm --accountId your-account.testnet
```

- Build and deploy the low-level contract:

```bash
cargo near deploy --wasmFile path/to/low-level-contract.wasm --accountId your-account.testnet
```

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 call-function '{"args": "value"}' --accountId your-account.testnet
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does not demonstrate the actual function defined in the contract (factorial). Please, write the example to the specific contract at hand, not just some placeholder


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-account.testnet` with your actual NEAR testnet account ID.

## 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.
76 changes: 74 additions & 2 deletions examples/factory-contract/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,75 @@
# 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 near deploy --wasmFile path/to/factory-contract.wasm --accountId your-account.testnet
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

This command is invalid. Please, test all the commands

Suggested change
cargo near deploy --wasmFile path/to/factory-contract.wasm --accountId your-account.testnet
cargo near deploy


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

```bash
near call your-factory-contract-account.testnet create_instance '{"args": "value"}' --accountId your-account.testnet
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

This command is outdated, please, use the new syntax (it is suggested to you in the output):

Suggested change
near call your-factory-contract-account.testnet create_instance '{"args": "value"}' --accountId your-account.testnet
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'


NOTE: Replace `path/to/factory-contract.wasm` with the actual path to your compiled WebAssembly file, and `your-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