Skip to content
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

Chore/add examples docs #1503

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,101 @@ Anything after the `--` double dash (the "slop") is parsed as arguments to the c

stellar contract invoke --id CCR6QKTWZQYW6YUJ7UP7XXZRLWQPFRV6SWBLQS4ZQOSAF4BOUD77OTE2 --source alice --network testnet -- hello --to world

## Contract Lifecycle

### Create Alice
To create an identity for Alice:
```
stellar keys generate alice
```

### Deploy Contract
To deploy a contract:
```
stellar contract deploy --wasm /path/to/contract.wasm --source alice --network testnet
```
This will then display the resulting contract ID:
```
CBB65ZLBQBZL5IYHDHEEPCVUUMFOQUZSQKAJFV36R7TZETCLWGFTRLOQ
```

### Initialize Contract
After deployment, initialize the contract with its ID:
```
stellar contract invoke --id <CONTRACT_ID> --source alice --network testnet -- initialize --param1 value1 --param2 value2
```

### Call Contract
Invoke a contract function:
```
stellar contract invoke --id <CONTRACT_ID> --source alice --network testnet -- function_name --arg1 value1 --arg2 value2
```

### View Contract State
To view the contract's state:
```
stellar contract read --id <CONTRACT_ID> --network testnet --source alice --durability <DURABILITY> --key <KEY>
```
Note `<DURABILITY>` is either `persistent` or `temporary`. `KEY` provides the key of the storage entry being read. The output will show the hash of the ledger entry along with two numbers, the last modified ledger and the live until ledger number. If no `KEY` is provided, the output will show the details for the contract instance.

### Manage Expired States
To bump the expiration of contract states:
```
stellar contract extend --id <CONTRACT_ID> --ledgers-to-extend 1000 --source alice --network testnet --durability <DURABILITY> --key <KEY>
```

This will extend the state of the instance provided by the given key to at least 1000 ledgers from the current ledger. If the live until ledger is greater than this value, nothing will be done. If no key is provided, the contract instance will be extended.

## Payments and Assets
Below describes the process for sending XLM, stellar classic, or a soroban asset.

### Fund the accounts
Set up and fund our accounts, Alice and Bob:
```
stellar keys generate alice --network testnet
stellar keys generate bob --network testnet
```

```
stellar keys fund alice --network testnet
stellar keys fund bob --network testnet
```

### Payment of XLM
First we need the address of the `stellar asset` contract which will allow us to transfer funds.
Obtain the `stellar asset` address for the `native` asset (XLM):

```
stellar contract id asset --asset native --source-account alice --network testnet
```
This will print out the contract id of the `stellar asset` contract used for sending `XLM`. If you would like to send a different token, change the `--asset` value to `<code>:<issuer id>` where `<code>` is the naming code of the asset, see [Naming an asset](https://developers.stellar.org/docs/tokens/control-asset-access#naming-an-asset), and `<issuer id>` is the account ID of the issuing account. For example, to obtain Alice's account ID, you can run

```
stellar keys address alice --network testnet
```

This will return an ID that starts with `G...`.

### Send XLM from Alice to Bob:
Once the contract ID for the desired asset transfer is obtained, invoke it to send the token.

First we will need to get the public key for Bob's account
```
stellar keys address bob --network testnet
```
Then invoke the `stellar asset` contract:
```
stellar contract invoke --id <asset contract ID> --source-account alice --network testnet -- transfer --to <Bob ID> --from alice --amount 100
```

We can check that Alice or Bob's new balance by invoking the same `stellar asset` contract and invoking the balance function:

```
stellar contract invoke --id <asset contract ID> --source-account alice --network testnet -- balance --id <account ID>
```

For more information on the functions available to the `stellar asset` contract, see the [token interface code](https://developers.stellar.org/docs/tokens/token-interface#code).


**Usage:** `stellar [OPTIONS] <COMMAND>`

Expand Down
Loading