-
Notifications
You must be signed in to change notification settings - Fork 250
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
MattCS2006
wants to merge
5
commits into
near:master
Choose a base branch
from
MattCS2006:Write-a-README-for-factory-contract-and-cross-contract-examples
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3f7b93a
Added the README's for cross-contract-calls & factory-contract.
MattCS2006 3d0ff38
Merge branch 'master' into Write-a-README-for-factory-contract-and-cr…
MattCS2006 80093eb
Changes on the usage and the markdown
MattCS2006 e21012e
Merge branch 'master' into Write-a-README-for-factory-contract-and-cr…
MattCS2006 7f96c35
docs: Update README for factory contract and cross-contract examples …
MattCS2006 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
- [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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Demonstrate calls to
simple_call
andcomplex_call
functions.