Skip to content

Commit

Permalink
Added near js commands for non-fungible-token example
Browse files Browse the repository at this point in the history
  • Loading branch information
Phuong Nguyen committed May 20, 2022
1 parent ccd5dcf commit dce047c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/cross-contract-call/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ near js call <contract-id> <function-name> [--args '<parameter>'] --deposit 0.1
```

or with the raw CLI call command:
```
```sh
near call jsvm.test.near call_js_contract --accountId <accountID> --base64 --args $(node encode_call.js <contract-account-id> <function-name> '[<parameter>]') --deposit 0.1
```
34 changes: 29 additions & 5 deletions examples/non-fungible-token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ Result contract bytecode file will be in `build/fungible-token.base64`. Intermed

Suppose JSVM contract was deployed to `jsvm.test.near`. Developer want to deploy the fungible token contract to `nft-jsvm.test.near`. Create `nft-jsvm.test.near`, `alice.test.near` and `bob.test.near` locally. Then:

```sh
near js deploy --accountId nft-jsvm.test.near --base64File build/non-fungible-token.base64 --deposit 0.1 --jsvm jsvm.test.near
```

or with the raw CLI call command:
```sh
export NEAR_ENV=local
near call jsvm.test.near deploy_js_contract --accountId nft-jsvm.test.near --args $(cat build/non-fungible-token.base64) --base64 --deposit 0.1
```
Expand All @@ -26,23 +31,42 @@ near call jsvm.test.near deploy_js_contract --accountId nft-jsvm.test.near --arg
Now we need to initialize the contract after deployment is ready, call the `init` method which will execute `new NftContract(owner_id, owner_by_id_prefix)` for the class.
Go back to the root dir of near-sdk-js, where we have a helper `encode-call.js`. Call it with:

```sh
near js call nft-jsvm.test.near init --args '["nft-jsvm.test.near", "prefix"]' --deposit 0.1 --accountId nft-jsvm.test.near --jsvm jsvm.test.near
```
near call jsvm.test.near call_js_contract --accountId nft-jsvm.testnet --base64 --args $(node encode_call.js nft-jsvm.testnet init '["nft-jsvm.testnet", "prefix"]') --deposit 0.1

or with the raw CLI call command:
```sh
near call jsvm.test.near call_js_contract --accountId nft-jsvm.test.near --base64 --args $(node encode_call.js nft-jsvm.test.near init '["nft-jsvm.test.near", "prefix"]') --deposit 0.1
```

## Call the contract
Under the root dir of near-sdk-js, call the `nftMint` and `nftToken` methods with:

```sh
near js call nft-jsvm.test.near nftMint --args '["1", "alice.test.near"]' --deposit 0.1 --accountId nft-jsvm.test.near --jsvm jsvm.test.near

near js call nft-jsvm.test.near nftToken --args '["1"]' --deposit 0.1 --accountId nft-jsvm.test.near --jsvm jsvm.test.near
```
near call jsvm.test.near call_js_contract --accountId nft-jsvm.testnet --base64 --args $(node encode_call.js nft-jsvm.testnet nftMint '["1", "alice.test.near"]') --deposit 0.1

near call jsvm.test.near call_js_contract --accountId nft-jsvm.testnet --base64 --args $(node encode_call.js nft-jsvm.testnet nftToken '["1"]')
or with the raw CLI call command:
```sh
near call jsvm.test.near call_js_contract --accountId nft-jsvm.test.near --base64 --args $(node encode_call.js nft-jsvm.test.near nftMint '["1", "alice.test.near"]') --deposit 0.1

near call jsvm.test.near call_js_contract --accountId nft-jsvm.test.near --base64 --args $(node encode_call.js nft-jsvm.test.near nftToken '["1"]')
```

To transfer the NFT to Bob and check its new owner:

```sh
near js call nft-jsvm.test.near nftTransfer --args '["bob.test.near", "1"]' --deposit 0.1 --accountId nft-jsvm.test.near --jsvm jsvm.test.near

near js call nft-jsvm.test.near nftToken --args '["1"]' --deposit 0.1 --accountId nft-jsvm.test.near --jsvm jsvm.test.near
```
near call jsvm.test.near call_js_contract --accountId nft-jsvm.testnet --base64 --args $(node encode_call.js nft-jsvm.testnet nftTransfer '["bob.test.near", "1"]') --deposit 0.1

near call jsvm.test.near call_js_contract --accountId nft-jsvm.testnet --base64 --args $(node encode_call.js nft-jsvm.testnet nftToken '["1"]')
or with the raw CLI call command:
```sh
near call jsvm.test.near call_js_contract --accountId nft-jsvm.test.near --base64 --args $(node encode_call.js nft-jsvm.test.near nftTransfer '["bob.test.near", "1"]') --deposit 0.1

near call jsvm.test.near call_js_contract --accountId nft-jsvm.test.near --base64 --args $(node encode_call.js nft-jsvm.test.near nftToken '["1"]')
```

0 comments on commit dce047c

Please sign in to comment.