-
Notifications
You must be signed in to change notification settings - Fork 252
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
3f7b93a
3d0ff38
80093eb
e21012e
7f96c35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
``` | ||
|
||
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. |
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 | ||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This command is invalid. Please, test all the commands
Suggested change
|
||||||
|
||||||
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 | ||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
|
||||||
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Demonstrate calls to |
||||||
|
||||||
- [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. |
There was a problem hiding this comment.
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