Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Use soroban contract init command in getting started tutorial (#730)
Browse files Browse the repository at this point in the history
* Updates to setup.mdx

* Rework hello-world to use the soroban contract init command

* Rework deploy-to-testnet.mdx to use init command

* Rework storing-data.mdx

* Rework storing-data.mdx

* Rework deploy-increment-contract.mdx

* Rework create-an-app

* Udpate deploy increment file name

* Apply suggestions from code review

Co-authored-by: Elliot Voris <[email protected]>

* Update re-installing to enable opt to not include version

Co-authored-by: Elliot Voris <[email protected]>

* Update docs/getting-started/setup.mdx

Co-authored-by: Elliot Voris <[email protected]>

* Address PR feedback

* Simplfy generate and fund command calls

* Update .env.example code block to match the fe template

* Small updates toe create-an-app.mdx

---------

Co-authored-by: Elliot Voris <[email protected]>
  • Loading branch information
elizabethengelman and ElliotFriend authored Mar 12, 2024
1 parent 48d0a25 commit 42faf1d
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 524 deletions.
331 changes: 134 additions & 197 deletions docs/getting-started/create-an-app.mdx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
sidebar_position: 40
title: 4. Deploy Incrementor
description: Deploy the Incrementor contract to Testnet.
title: 4. Deploy the Increment Contract
description: Deploy the Increment contract to Testnet.
---

<head>
<meta charSet="utf-8" />
<meta
property="og:title"
content="Deploy the Incrementor contract to Testnet."
content="Deploy the Increment contract to Testnet."
/>
<meta
property="og:description"
content="Deploy the Incrementor contract to Testnet."
content="Deploy the Increment contract to Testnet."
/>
<link
rel="canonical"
Expand All @@ -24,17 +24,17 @@ description: Deploy the Incrementor contract to Testnet.

It's worth knowing that `deploy` is actually a two-step process.

1. Upload the contract bytes to the network. Soroban currently refers to this as _installing_ the contract—from the perspective of the blockchain itself, this is a reasonable metaphor. This uploads the bytes of the contract to the network, indexing it by its hash. This contract code can now be referenced by multiple contracts, which means they would have the exact same _behavior_ but separate storage state.
1. **Upload the contract bytes to the network.** Soroban currently refers to this as _installing_ the contract—from the perspective of the blockchain itself, this is a reasonable metaphor. This uploads the bytes of the contract to the network, indexing it by its hash. This contract code can now be referenced by multiple contracts, which means they would have the exact same _behavior_ but separate storage state.

2. Instantiate the contract. This actually creates what you probably think of as a Smart Contract. It makes a new contract ID, and associates it with the contract bytes that were uploaded in the previous step.
2. **Instantiate the contract.** This actually creates what you probably think of as a Smart Contract. It makes a new contract ID, and associates it with the contract bytes that were uploaded in the previous step.

You can run these two steps separately. Let's try it with the Incrementor contract:
You can run these two steps separately. Let's try it with the Increment contract:

```bash
soroban contract install \
--network testnet \
--source alice \
--wasm target/wasm32-unknown-unknown/release/incrementor.wasm
--wasm target/wasm32-unknown-unknown/release/soroban_increment_contract.wasm
```

This returns the hash of the Wasm bytes. Now you can use `--wasm-hash` with `deploy` rather than `--wasm`. Let's also automatically pipe the returned contract ID into a file in the `.soroban` directory, so that when you search your command history and reuse the deploy command in the future, you don't forget that step (you might want to go back and do something similar with the Hello World deploy, too):
Expand All @@ -44,20 +44,20 @@ soroban contract deploy \
--wasm-hash [paste the output from the last command] \
--source alice \
--network testnet \
> .soroban/incrementor-id
> .soroban/contract-ids/soroban_increment_contract.txt
```

You can check that it saved the contract ID correctly:

```bash
cat .soroban/incrementor-id
cat .soroban/contract-ids/soroban_increment_contract.txt
```

Now you can interact with it over RPC like you did with the Hello World contract:

```bash
soroban contract invoke \
--id $(cat .soroban/incrementor-id) \
--id $(cat .soroban/contract-ids/soroban_increment_contract.txt) \
--source alice \
--network testnet \
-- \
Expand Down
22 changes: 12 additions & 10 deletions docs/getting-started/deploy-to-testnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ To recap what we've done so far, in [Setup](setup.mdx):
- configured the soroban-cli to communicate with the Soroban Testnet via RPC
- and configured an identity to sign transactions

In [Hello World](hello-world.mdx) we wrote a simple contract, and now we are ready to deploy that contract to Testnet, and interact with it.
In [Hello World](hello-world.mdx) we created a `hello-world` project, and learned how to test and build the `HelloWorld` contract. Now we are ready to deploy that contract to Testnet, and interact with it.

## Deploy

To deploy your Hello Soroban contract, run the following command:
To deploy your HelloWorld contract, run the following command:

```bash
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/hello_soroban.wasm \
--wasm target/wasm32-unknown-unknown/release/soroban_hello_world_contract.wasm \
--source alice \
--network testnet
```

This returns the ID of the contract, starting with a `C`. Let's put it somewhere semi-permanent so we can use it later. Copy that value and put it into a file in the `.soroban` directory called `hello-id`. You may need to create the `.soroban` folder first with `mkdir .soroban`.
This returns the ID of the contract, starting with a `C`. Let's put it somewhere semi-permanent so we can use it later. Copy that value and put it into a file in the `.soroban/contract-ids` directory called `soroban_hello_world_contract.txt`.

```bash
echo "C...[your contract id here]" > .soroban/hello-id
echo "C...[your contract id here]" > .soroban/contract-ids/soroban_hello_world_contract.txt
```

## Interact
Expand All @@ -56,11 +56,15 @@ In the background, the CLI is making RPC calls. For information on that checkout

:::

Here we're setting the `to` argument to `RPC`. This again makes use of command expansion `$(…)`; see the note about that in the [Configure an Identity](setup.mdx#configure-an-identity) section of Setup.
:::tip Command Expansion `$(…)`

This uses [command expansion](https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html), which only works with bash-compatible shells. If you are using Windows or some other shell, you will need to copy the output of `soroban config…` and paste it into the `curl` command, or figure out how command expansion works in your shell.

:::

```bash
soroban contract invoke \
--id $(cat .soroban/hello-id) \
--id $(cat .soroban/contract-ids/soroban_hello_world_contract.txt) \
--source alice \
--network testnet \
-- \
Expand Down Expand Up @@ -99,6 +103,4 @@ In this lesson, we learned how to:
- deploy a contract to Testnet
- interact with a deployed contract

You shouldn't have any changes to commit to git, because we didn't change any code in this lesson!

Next we'll add a new contract to this project, reorganizing the project as a multi-contract project using Cargo Workspaces. The new contract will show off a little bit of Soroban's storage capabilities.
Next we'll add a new contract to this project, and see how our workspace can accommodate a multi-contract project. The new contract will show off a little bit of Soroban's storage capabilities.
Loading

0 comments on commit 42faf1d

Please sign in to comment.