-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the optimized build instructions inside the build page to shorte…
…n the list of tutorials (#190)
- Loading branch information
1 parent
6b0b019
commit 2c2d793
Showing
4 changed files
with
175 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
docs/tutorials/run-on-local-network.mdx → docs/tutorials/deploy-to-local-network.mdx
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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
sidebar_position: 11 | ||
title: Invoking Contracts with Stellar Transactions | ||
--- | ||
|
||
Stellar supports invoking and deploying contracts with a new Operation named `InvokeHostFunctionOp`. The [`soroban-cli`] abstracts these details away from the | ||
user, but SDKs do not yet and if you're building a dapp you'll probably find yourself building the XDR transaction to submit to | ||
the network. | ||
|
||
The `InvokeHostFunctionOp` can be used to invoke host functions. Host functions are built-in to Soroban and give the invoker access to: | ||
- Invoking contract functions. | ||
- Deploying new contracts. | ||
- Deploying token contracts for Stellar Assets. | ||
|
||
[`soroban-cli`]: ../getting-started/setup#install-the-soroban-cli | ||
|
||
## InvokeHostFunctionOp | ||
|
||
The XDR of `HostFunction` and `InvokeHostFunctionOp` below can be found | ||
[here](https://github.com/stellar/stellar-xdr-next/blob/161e2e5b64425a49f9ccfef7f732ae742ed5eec4/Stellar-transaction.x#L477-L496) | ||
```c++ | ||
enum HostFunction | ||
{ | ||
HOST_FN_INVOKE_CONTRACT = 0, | ||
HOST_FN_CREATE_CONTRACT_WITH_ED25519 = 1, | ||
HOST_FN_CREATE_CONTRACT_WITH_SOURCE_ACCOUNT = 2, | ||
HOST_FN_CREATE_TOKEN_CONTRACT_WITH_SOURCE_ACCOUNT = 3, | ||
HOST_FN_CREATE_TOKEN_CONTRACT_WITH_ASSET = 4 | ||
}; | ||
|
||
struct InvokeHostFunctionOp | ||
{ | ||
// The host function to invoke | ||
HostFunction function; | ||
|
||
// Parameters to the host function | ||
SCVec parameters; | ||
|
||
// The footprint for this invocation | ||
LedgerFootprint footprint; | ||
}; | ||
``` | ||
|
||
### Function | ||
The `parameters` in `InvokeHostFunctionOp` will be forwarded to the | ||
`HostFunction` specifed in `function`. The options are - | ||
1. `HOST_FN_INVOKE_CONTRACT` | ||
- This will call the `call_n` host function, invoking a contract function. | ||
- `parameters` is | ||
expected to contain the contract id, contract function name, and the | ||
parameters to the contract function being invoked. | ||
2. `HOST_FN_CREATE_CONTRACT_WITH_ED25519` | ||
- This is disabled for now. Calling it will result in an error. | ||
3. `HOST_FN_CREATE_CONTRACT_WITH_SOURCE_ACCOUNT` | ||
- This will call the `create_contract_from_source_account` host function, | ||
creating a contract using the stellar source account that submitted the | ||
transaction. The contract id will be the SHA256 hash of | ||
[this](https://github.com/stellar/stellar-xdr-next/blob/161e2e5b64425a49f9ccfef7f732ae742ed5eec4/Stellar-transaction.x#L594) `HashIDPreimage`. | ||
- `parameters` is expected to contain two elements: the WASM contract code and a | ||
salt. | ||
4. `HOST_FN_CREATE_TOKEN_CONTRACT_WITH_SOURCE_ACCOUNT` | ||
- This will call the `create_token_from_source_account` host function, | ||
creating a [built-in token contract] using the stellar source account that submitted the | ||
transaction. The contract id will be the SHA256 hash of | ||
[this](https://github.com/stellar/stellar-xdr-next/blob/161e2e5b64425a49f9ccfef7f732ae742ed5eec4/Stellar-transaction.x#L594) `HashIDPreimage`. | ||
- `parameters` is expected to contain a salt. | ||
5. `HOST_FN_CREATE_TOKEN_CONTRACT_WITH_ASSET` | ||
- This will call the `create_token_from_asset` host function, creating a | ||
[built-in token contract] that wraps a classic Stellar asset. | ||
The contract id will be the SHA256 hash of | ||
[this](https://github.com/stellar/stellar-xdr-next/blob/161e2e5b64425a49f9ccfef7f732ae742ed5eec4/Stellar-transaction.x#L592) `HashIDPreimage`. `create_token_from_asset` will also initialize the token | ||
contract, so the user is not expected to call any intialize functions. | ||
- `parameters` is expected to contain a xdr `Asset`. | ||
|
||
[built-in token contract]: ../built-in-contracts/token-contract.mdx | ||
|
||
### Parameters | ||
This `SCVec` contains the parameters that will be passed to the host function that is being invoked. | ||
|
||
### Footprint | ||
The footprint must contain the `LedgerKeys` that will be read and/or written. More | ||
information about the footprint can be found in the advanced section of [interacting with contracts](interacting-with-contracts#storage-footprint-and-preflight). |