-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
77 deletions.
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,100 +1,49 @@ | ||
# Hello NEAR Contract | ||
# SFFL Agreement Registry | ||
|
||
The smart contract exposes two methods to enable storing and retrieving a greeting in the NEAR network. | ||
> [!NOTE] | ||
> This contract is not being used in the current phase. | ||
```rust | ||
const DEFAULT_GREETING: &str = "Hello"; | ||
This contract is a prototype of how SFFL attestations could be done using a | ||
NEAR smart contract. | ||
|
||
#[near_bindgen] | ||
#[derive(BorshDeserialize, BorshSerialize)] | ||
pub struct Contract { | ||
greeting: String, | ||
} | ||
Through this contract, operators can link their Ethereum addresses to a NEAR | ||
account by signing an [EIP712](https://eips.ethereum.org/EIPS/eip-712) message, | ||
and can then submit their BLS signatures to SFFL messages and tasks to NEAR, | ||
which will be available for any external actors. | ||
|
||
impl Default for Contract { | ||
fn default() -> Self { | ||
Self { greeting: DEFAULT_GREETING.to_string() } | ||
} | ||
} | ||
The aggregation step could be then done by an off-chain actor, or, which would | ||
be even more ideal, in a NEAR smart contract itself. | ||
|
||
#[near_bindgen] | ||
impl Contract { | ||
// Public: Returns the stored greeting, defaulting to 'Hello' | ||
pub fn get_greeting(&self) -> String { | ||
return self.greeting.clone(); | ||
} | ||
|
||
// Public: Takes a greeting, such as 'howdy', and records it | ||
pub fn set_greeting(&mut self, greeting: String) { | ||
// Record a log permanently to the blockchain! | ||
log!("Saving greeting {}", greeting); | ||
self.greeting = greeting; | ||
} | ||
} | ||
``` | ||
|
||
<br /> | ||
|
||
# Quickstart | ||
|
||
1. Make sure you have installed [rust](https://rust.org/). | ||
2. Install the [`NEAR CLI`](https://github.com/near/near-cli#setup) | ||
|
||
<br /> | ||
|
||
## 1. Build, Test and Deploy | ||
## Build | ||
To build the contract you can execute the `./build.sh` script, which will in turn run: | ||
|
||
```bash | ||
rustup target add wasm32-unknown-unknown | ||
cargo build --target wasm32-unknown-unknown --release | ||
``` | ||
|
||
Then, run the `./deploy.sh` script, which will in turn run: | ||
|
||
## Test | ||
You can also run the `./test.sh` script, which will execute: | ||
```bash | ||
near dev-deploy --wasmFile ./target/wasm32-unknown-unknown/release/sffl-agreement-registry.wasm | ||
``` | ||
|
||
the command [`near dev-deploy`](https://docs.near.org/tools/near-cli#near-dev-deploy) automatically creates an account in the NEAR testnet, and deploys the compiled contract on it. | ||
cargo test | ||
|
||
Once finished, check the `./neardev/dev-account` file to find the address in which the contract was deployed: | ||
|
||
```bash | ||
cat ./neardev/dev-account | ||
# e.g. dev-1659899566943-21539992274727 | ||
./build.sh | ||
cd sandbox-rs | ||
cargo run --example sandbox "../../../../target/wasm32-unknown-unknown/release/sffl_agreement_registry.wasm" | ||
``` | ||
|
||
<br /> | ||
|
||
## 2. Retrieve the Greeting | ||
|
||
`get_greeting` is a read-only method (aka `view` method). | ||
|
||
`View` methods can be called for **free** by anyone, even people **without a NEAR account**! | ||
## Deploy | ||
To deploy, run the `./deploy.sh` script, which will in turn run: | ||
|
||
```bash | ||
# Use near-cli to get the greeting | ||
near view <dev-account> get_greeting | ||
near dev-deploy --wasmFile ../../../target/wasm32-unknown-unknown/release/sffl_agreement_registry.wasm | ||
``` | ||
|
||
<br /> | ||
|
||
## 3. Store a New Greeting | ||
`set_greeting` changes the contract's state, for which it is a `change` method. | ||
|
||
`Change` methods can only be invoked using a NEAR account, since the account needs to pay GAS for the transaction. In this case, we are asking the account we created in step 1 to sign the transaction. | ||
|
||
```bash | ||
# Use near-cli to set a new greeting | ||
near call <dev-account> set_greeting '{"greeting":"howdy"}' --accountId <dev-account> | ||
``` | ||
the command [`near dev-deploy`](https://docs.near.org/tools/near-cli#near-dev-deploy) automatically creates an account in the NEAR testnet, and deploys the compiled contract on it. | ||
|
||
**Tip:** If you would like to call `set_greeting` using your own account, first login into NEAR using: | ||
Once finished, check the `./neardev/dev-account` file to find the address in which the contract was deployed: | ||
|
||
```bash | ||
# Use near-cli to login your NEAR account | ||
near login | ||
``` | ||
|
||
and then use the logged account to sign the transaction: `--accountId <your-account>`. | ||
cat ./neardev/dev-account | ||
# e.g. dev-1659899566943-21539992274727 | ||
``` |