Skip to content

Commit

Permalink
updated cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
garikbesson committed Aug 27, 2024
1 parent e57ea68 commit 1ff2601
Show file tree
Hide file tree
Showing 60 changed files with 3,869 additions and 1,409 deletions.
67 changes: 53 additions & 14 deletions docs/1.concepts/protocol/account-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ id: account-id
title: Address (Account ID)
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

NEAR accounts are identified by a unique address, which take one of two forms:
1. [**Implicit addresses**](#implicit-address), which are 64 characters long (e.g. `fb9243ce...`)
2. [**Named addresses**](#named-address), which are simpler to remember and act as domains (e.g. `alice.near`)
Expand Down Expand Up @@ -30,12 +33,12 @@ Implicit accounts always *exist*, and thus do not need to be created. However, i
The simplest way to obtain a public / private key that represents an account is using the [NEAR CLI](../../4.tools/cli.md)

```bash
near generate-key
near account create-account fund-later use-auto-generation save-to-folder ~/.near-credentials/implicit

# The file "~/.near-credentials/testnet/8bca86065be487de45e795b2c3154fe834d53ffa07e0a44f29e76a2a5f075df8.json" was saved successfully

# Output
# Seed phrase: lumber habit sausage used zebra brain border exist meat muscle river hidden
# Key pair: {"publicKey":"ed25519:AQgnQSR1Mp3v7xrw7egJtu3ibNzoCGwUwnEehypip9od","secretKey":"ed25519:51qTiqybe8ycXwPznA8hz7GJJQ5hyZ45wh2rm5MBBjgZ5XqFjbjta1m41pq9zbRZfWGUGWYJqH4yVhSWoW6pYFkT"}
# Implicit account: 8bca86065be487de45e795b2c3154fe834d53ffa07e0a44f29e76a2a5f075df8
# Here is your console command if you need to script it or re-run:
# near account create-account fund-later use-auto-generation save-to-folder ~/.near-credentials/implicit
```

</details>
Expand Down Expand Up @@ -63,21 +66,57 @@ Anyone can create a `.near` or `.testnet` account, you just to call the `create_

Named accounts are created by calling the `create_account` method of the network's top-level account - `testnet` on testnet, and `near` on mainnet.

```bash
near call testnet create_account '{"new_account_id": "new-acc.testnet", "new_public_key": "ed25519:<data>"}' --deposit 0.00182 --accountId funding-account.testnet
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">

```bash
near call testnet create_account '{"new_account_id": "new-acc.testnet", "new_public_key": "ed25519:<data>"}' --deposit 0.00182 --accountId funding-account.testnet --networkId testnet
```
</TabItem>

<TabItem value="full" label="Full">

```bash
near contract call-function as-transaction testnet create_account json-args '{"new_account_id": "new-acc.testnet", "new_public_key": "ed25519:<data>"}' prepaid-gas '100.0 Tgas' attached-deposit '0.00182 NEAR' sign-as funding-account.testnet network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>

We abstract this process in the [NEAR CLI](../../4.tools/cli.md) with the following command:

```bash
near create_account new-acc.testnet --useAccount funding-account.testnet --publicKey ed25519:<data>
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">

```bash
near create-account new-acc.testnet --useAccount funding-account.testnet --publicKey ed25519:<data>
```
</TabItem>

<TabItem value="full" label="Full">

```bash
near account create-account fund-myself new-acc.testnet '1 NEAR' use-manually-provided-public-key ed25519:<data> sign-as funding-account.testnet network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>

You can use the same command to create sub-accounts of an existing named account:

```bash
near create_account sub-acc.new-acc.testnet --useAccount new-acc.testnet
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">

```bash
near create-account sub-acc.new-acc.testnet --useAccount new-acc.testnet
```
</TabItem>

<TabItem value="full" label="Full">

```bash
near account create-account fund-myself sub-acc.new-acc.testnet '1 NEAR' autogenerate-new-keypair save-to-keychain sign-as new-acc.testnet network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>

</details>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: relayer-gas-example
title: Multichain Relayer and Gas Station example
sidebar_label: Relayer + Gas Station
---
import {CodeTabs, Language, Github} from "@site/src/components/codetabs"
import {CodeTabs, Language, Github} from "@site/src/components/codetabs";
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Expand Down Expand Up @@ -124,34 +124,82 @@ This test is a good way to debug issues if any individual part of the system isn
The following instructions are only need to be called once to initialize the account on the Gas Station. Make sure to replace the `<account_id>` (string) with the account you want to initialize and `<token_id>` (integer) with the token id of the NFT you minted in step 2:
1. Registration / Storage Deposit:
```shell
near contract call-function as-transaction v2.nft.kagi.testnet \
storage_deposit json-args {} prepaid-gas '100.0 Tgas' attached-deposit '1 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">
```bash
near call v2.nft.kagi.testnet storage_deposit '{}' --deposit 1 --gas 100000000000000 --accountId <account_id>.testnet
```
</TabItem>
<TabItem value="full" label="Full">
```bash
near contract call-function as-transaction v2.nft.kagi.testnet \
storage_deposit json-args {} prepaid-gas '100.0 Tgas' attached-deposit '1 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>
2. Mint NFT - make sure to save the token id from the logs of this call
```shell
near contract call-function as-transaction v2.nft.kagi.testnet \
mint json-args {} prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">
```bash
near call v2.nft.kagi.testnet mint '{}' --gas 100000000000000 --accountId <account_id>.testnet
```
</TabItem>
<TabItem value="full" label="Full">
```bash
near contract call-function as-transaction v2.nft.kagi.testnet \
mint json-args {} prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>
3. Approve the Gas Station for this Token (use or use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction v2.nft.kagi.testnet \
ckt_approve_call json-args '{"token_id":"<token_id>","account_id":"canhazgas.testnet","msg":""}' \
prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">
```bash
near call v2.nft.kagi.testnet ckt_approve_call '{"token_id":"<token_id>","account_id":"canhazgas.testnet","msg":""}' --gas 100000000000000 --accountId <account_id>.testnet
```
</TabItem>
<TabItem value="full" label="Full">
```bash
near contract call-function as-transaction v2.nft.kagi.testnet \
ckt_approve_call json-args '{"token_id":"<token_id>","account_id":"canhazgas.testnet","msg":""}' \
prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>
### Manual test steps
1. Get paymaster info for the chain you want to send to from the gas station contract, then optionally manually set nonces (use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction canhazgas.testnet \
get_paymasters json-args '{"chain_id": "<chain_id>"}' \
prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">
```bash
near call canhazgas.testnet get_paymasters '{"chain_id": "<chain_id>"}' --gas 100000000000000 --accountId <account_id>.testnet
```
</TabItem>
<TabItem value="full" label="Full">
```bash
near contract call-function as-transaction canhazgas.testnet \
get_paymasters json-args '{"chain_id": "<chain_id>"}' \
prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>
which returns something like:
```js
--- Result -------------------------
Expand All @@ -166,15 +214,27 @@ The following instructions are only need to be called once to initialize the acc
------------------------------------
```
1. You may need to manually set the nonce for the paymaster to be able to send the transaction (use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction canhazgas.testnet \
get_paymasters json-args '{"chain_id": "<chain_id>"}' \
prepaid-gas '100.000 Tgas' \
attached-deposit '0 NEAR' \
sign-as <account_id>.testnet \
network-config testnet \
sign-with-keychain send
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">
```bash
near call canhazgas.testnet get_paymasters '{"chain_id": "<chain_id>"}' --gas 100000000000000 --accountId <account_id>.testnet
```
</TabItem>
<TabItem value="full" label="Full">
```bash
near contract call-function as-transaction canhazgas.testnet \
get_paymasters json-args '{"chain_id": "<chain_id>"}' \
prepaid-gas '100.000 Tgas' \
attached-deposit '0 NEAR' \
sign-as <account_id>.testnet \
network-config testnet \
sign-with-keychain send
```
</TabItem>
</Tabs>
2. Update the transaction details of the EVM transaction you want to send in `generate_eip1559_rlp_hex()` test in [`tests/tests.rs`](https://github.com/near/multichain-relayer-server/blob/main/tests/tests.rs) then run the script and save the RLP hex string output.
1. If that doesn't work, try running [`generate_rlp_evm_txn.py`](https://github.com/near/multichain-relayer-server/blob/main/integration_tests/generate_rlp_evm_txn.py)

Expand Down Expand Up @@ -216,13 +276,27 @@ Python and Rust output different hex RLP encoded transactions.
You also need to paste in the RLP generated hex for the EVM transaction you want on the other chain generated in step 1.
When it asks you to send or display, choose send.
For example (use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction canhazgas.testnet \
create_transaction json-args '{"transaction_rlp_hex":"eb80851bf08eb000825208947b965bdb7f0464843572eb2b8c17bdf27b720b14872386f26fc1000080808080","use_paymaster":true,"token_id":"<token_id>"}' \
prepaid-gas '100.000 TeraGas' attached-deposit '<deposit_in_near> NEAR' \
sign-as <account_id>.testnet \
network-config testnet sign-with-keychain send
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">
```bash
near call canhazgas.testnet create_transaction '{"transaction_rlp_hex":"eb80851bf08eb000825208947b965bdb7f0464843572eb2b8c17bdf27b720b14872386f26fc1000080808080","use_paymaster":true,"token_id":"<token_id>"}' --deposit <deposit_in_near> --gas 100000000000000 --accountId <account_id>.testnet
```
</TabItem>
<TabItem value="full" label="Full">
```bash
near contract call-function as-transaction canhazgas.testnet \
create_transaction json-args '{"transaction_rlp_hex":"eb80851bf08eb000825208947b965bdb7f0464843572eb2b8c17bdf27b720b14872386f26fc1000080808080","use_paymaster":true,"token_id":"<token_id>"}' \
prepaid-gas '100.000 TeraGas' attached-deposit '<deposit_in_near> NEAR' \
sign-as <account_id>.testnet \
network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>
which returns something like:
```
--- Result -------------------------
Expand All @@ -233,15 +307,27 @@ Python and Rust output different hex RLP encoded transactions.
------------------------------------
```
6. Get the `"id"` from the receipts from the result in the previous step, and use that to call `sign_next` twice (use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction canhazgas.testnet \
sign_next json-args '{"id":"<id>"}' \
prepaid-gas '300.0 Tgas' \
attached-deposit '0 NEAR' \
sign-as <account_id>.testnet \
network-config testnet \
sign-with-keychain send
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">
```bash
near call canhazgas.testnet sign_next '{"id":"<id>"}' --gas 300000000000000 --accountId <account_id>.testnet
```
</TabItem>
<TabItem value="full" label="Full">
```bash
near contract call-function as-transaction canhazgas.testnet \
sign_next json-args '{"id":"<id>"}' \
prepaid-gas '300.0 Tgas' \
attached-deposit '0 NEAR' \
sign-as <account_id>.testnet \
network-config testnet \
sign-with-keychain send
```
</TabItem>
</Tabs>
> **Note:** this step will be updated soon, as support for yield/resume calls is implemented on MPC contract.
Expand All @@ -255,9 +341,21 @@ Python and Rust output different hex RLP encoded transactions.
Instead of creating a signed transaction and calling the gas station contract to sign it, you can get the recently signed transactions by calling the contract while replacing the `blockheight` with a more recent block height (use `canhazgas.near` for mainnet):
```sh
near contract call-function as-read-only canhazgas.testnet list_signed_transaction_sequences_after json-args '{"block_height":"157111000"}' network-config testnet now
```
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">
```bash
near view canhazgas.testnet list_signed_transaction_sequences_after '{"block_height":"157111000"}' --networkId testnet
```
</TabItem>
<TabItem value="full" label="Full">
```bash
near contract call-function as-read-only canhazgas.testnet list_signed_transaction_sequences_after json-args '{"block_height":"157111000"}' network-config testnet now
```
</TabItem>
</Tabs>
This will return something like the output below. Take an individual entry in the list of JSONs and send that as the payload of a `POST` request to the `/send_funding_and_user_signed_txns` endpoint:
Expand Down
8 changes: 4 additions & 4 deletions docs/2.build/2.smart-contracts/anatomy/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ hide_table_of_contents: true

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import {CodeTabs, Language, Github} from "@site/src/components/codetabs"
import CodeBlock from '@theme/CodeBlock'
import {CodeTabs, Language, Github} from "@site/src/components/codetabs";
import CodeBlock from '@theme/CodeBlock';
import {ExplainCode, Block, File} from '@site/src/components/CodeExplainer/code-explainer';

Smart contracts expose functions so users can interact with them. There are different types of functions including `read-only`, `private` and `payable`.
Expand Down Expand Up @@ -224,9 +224,9 @@ They are useful to return hardcoded values on the contract.

</Block>

<File language="js" fname="auction" url="https://github.com/near-examples/auction-examples/blob/main/contract-ts/src/contract.ts" start="2" end="51" />
<File language="js" fname="auction" url="https://github.com/near-examples/auction-examples/blob/main/contract-ts/01-basic-auction/src/contract.ts" start="2" end="51" />

<File language="rust" fname="auction" url="https://github.com/near-examples/auction-examples/blob/main/contract-rs/src/lib.rs" start="2" end="68" />
<File language="rust" fname="auction" url="https://github.com/near-examples/auction-examples/blob/main/contract-rs/01-basic-auction/src/lib.rs" start="2" end="72" />

<CodeBlock language="js" fname="example">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ id: serialization-protocols
title: Serialization Protocols
---

import {Github} from "@site/src/components/codetabs";
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import {Github} from "@site/src/components/codetabs";

Serialization formats within the SDK define how data structures are translated into bytes which are needed for passing data into methods of the smart contract or storing data in state. For the case of method parameters, [JSON](https://www.json.org/json-en.html) (default) and [Borsh](https://borsh.io/) are supported with the SDK and for storing data on-chain Borsh is used.

Expand Down Expand Up @@ -54,14 +54,14 @@ Note that this is using this simple struct:

To call this with NEAR CLI, use a command similar to this:

<Tabs className="language-tabs" groupId="code-tabs">
<TabItem value="near-cli">
<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">

```bash
near call rust-status-message.demo.testnet set_status_borsh --base64 'DAAAAEFsb2hhIGhvbnVhIQ==' --accountId demo.testnet
```
</TabItem>
<TabItem value="near-cli-rs">
<TabItem value="full" label="Full">

```bash
near contract call-function as-transaction rust-status-message.demo.testnet set_status_borsh base64-args 'DAAAAEFsb2hhIGhvbnVhIQ==' prepaid-gas '30 TeraGas' attached-deposit '0 NEAR' sign-as demo.testnet network-config testnet sign-with-keychain send
Expand Down
Loading

0 comments on commit 1ff2601

Please sign in to comment.