-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): add cosmpy missing docs (#131)
Co-authored-by: Joshua Croft <[email protected]> Co-authored-by: josh <[email protected]>
- Loading branch information
1 parent
4569a62
commit 4b917a7
Showing
13 changed files
with
2,611 additions
and
2 deletions.
There are no files selected for viewing
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,67 @@ | ||
# Smart contracts | ||
|
||
## Deploy a smart contract | ||
|
||
CosmPy offers the possibility to easily deploy **smart contracts** using `LedgerContract` object. For this, you will need the **path** to where the contract is stored (in this case `simple.wasm`), a [`LedgerClient` ↗️](/guides/fetch-network/cosmpy/establishing-node-connection) and a [Wallet ↗️](/guides/fetch-network/cosmpy/creating-wallet): | ||
|
||
```py copy | ||
from cosmpy.aerial.contract import LedgerContract | ||
|
||
PATH = "contracts/simple/simple.wasm" | ||
|
||
contract = LedgerContract(PATH, ledger_client) | ||
contract.deploy({}, wallet) | ||
``` | ||
|
||
## Interact with smart contracts | ||
|
||
We can now start interacting with any smart contract in different ways by executing one of the following operations. | ||
|
||
### Retrieve contract address | ||
|
||
After deployment, you can obtain the address of the deployed contract on the network using the `address` method in the following way: | ||
|
||
```py copy | ||
print(f"Contract deployed at: {contract.address}") | ||
``` | ||
|
||
### Query contract's state variables | ||
|
||
We can also query the values of the contract's state variables using the `query` method and provide a dictionary specifying the query information: | ||
|
||
```py copy | ||
result = contract.query({"get": {"owner": wallet}}) | ||
print("Initial state:", result) | ||
``` | ||
|
||
### Set contract's state variables | ||
|
||
We can update the contract's state variables by using the `execute` method and by providing a dictionary specifying the update wanted. Use the wait_to_complete() method to wait for the execution to finish. | ||
|
||
The following code sets the state variable `value` to `foobar`: | ||
|
||
```py copy | ||
contract.execute({"set": {"value": "foobar"}}, wallet).wait_to_complete() | ||
``` | ||
|
||
Once you set a state variable to its updated value, you can query it again to confirm such changes took place effectively. Considering the example above, we can check if changes were set correctly in the following way: | ||
|
||
```py copy | ||
result = contract.query({"get": {"owner": wallet)}}) | ||
print("State after set:", result) | ||
``` | ||
|
||
### Clear state variables | ||
|
||
We can clear the contract's state variables using the `execute` method in the following way: | ||
|
||
```py copy | ||
contract.execute({"clear": {}}, wallet).wait_to_complete() | ||
``` | ||
|
||
And check if operations went smoothly by running: | ||
|
||
```py copy | ||
result = contract.query({"get": {"owner": wallet}}) | ||
print("State after clear:", result) | ||
``` |
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,8 @@ | ||
{ | ||
"stake-auto-compounder": "Stake auto-compounder️", | ||
"stake-optimizer": "Stake optimizer️", | ||
"oracles": "Oracles \uD83D\uDD2E", | ||
"wallet-top-up": "Wallet top-up \uD83D\uDCB5", | ||
"liquidity-pool": "Liquidity pool", | ||
"swap_automation": "Swap automation \uD83D\uDD04" | ||
} |
Oops, something went wrong.