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

[Move examples] Fix example code #2119

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions developer-docs-site/docs/tutorials/first-coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Update the module with Alice's address, build, copy to the provided path, and pr

## Step 2) Initialize MoonCoin

The MoonCoin module has alreayd been deployed. The next step is to initialize MoonCoin. In this example, we'll be using 0x1::ManagedCoin::initialize since we want the ability to mint/burn our new MoonCoin. This adds standard functionalities to MoonCoin such as transfer, mint, burn and standard events (register, deposit, withdraw).
The MoonCoin module has alreayd been deployed. The next step is to initialize MoonCoin. In this example, we'll be using 0x1::managed_coin::initialize since we want the ability to mint/burn our new MoonCoin. This adds standard functionalities to MoonCoin such as transfer, mint, burn and standard events (register, deposit, withdraw).

<Tabs>
<TabItem value="python" label="Python" default>
Expand Down Expand Up @@ -188,7 +188,7 @@ To register, the recipient just needs to call ```0x1::coin::register<CoinType>``

## Step 4) Mint MoonCoin to the recipient as the owner of the MoonCoin

When initializing a new Coin (Step 2), the owning account receives capabilities to mint/burn the new coin. The owner account can mint MoonCoin by calling 0x1::ManagedCoin::mint.
When initializing a new Coin (Step 2), the owning account receives capabilities to mint/burn the new coin. The owner account can mint MoonCoin by calling 0x1::managed_coin::mint.

<Tabs>
<TabItem value="python" label="Python" default>
Expand Down
7 changes: 4 additions & 3 deletions developer-docs-site/static/examples/python/first_coin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize_coin(self, account_from: Account) -> Optional[str]:
""" Initialize a new coin with the given coin type. """
payload = {
"type": "script_function_payload",
"function": "0x1::ManagedCoin::initialize",
"function": "0x1::managed_coin::initialize",
"type_arguments": [f"0x{account_from.address()}::MoonCoin::MoonCoin"],
"arguments": [
"Moon Coin".encode("utf-8").hex(),
Expand Down Expand Up @@ -54,7 +54,7 @@ def mint_coin(

payload = {
"type": "script_function_payload",
"function": "0x1::ManagedCoin::mint",
"function": "0x1::managed_coin::mint",
"type_arguments": [f"0x{account_coin_owner.address()}::MoonCoin::MoonCoin"],
"arguments": [
receiver_address,
Expand All @@ -73,7 +73,8 @@ def get_balance(
) -> str:
""" Returns the coin balance of the given account """

return self.account_resource(account_address, f"0x1::coin::CoinStore<0x{coin_type_address}::MoonCoin::MoonCoin>")
balance = self.account_resource(account_address, f"0x1::coin::CoinStore<0x{coin_type_address}::MoonCoin::MoonCoin>")
return balance["data"]["coin"]["value"]
#<:!:section_4

if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl FirstCoinClient {
pub fn initialize_coin(&self, account_from: &mut Account) -> String {
let payload = serde_json::json!({
"type": "script_function_payload",
"function": "0x1::ManagedCoin::initialize",
"function": "0x1::managed_coin::initialize",
"type_arguments": [format!("0x{}::MoonCoin::MoonCoin", account_from.address())],
"arguments": [
hex::encode("Moon Coin".as_bytes()),
Expand Down Expand Up @@ -58,7 +58,7 @@ impl FirstCoinClient {
) -> String {
let payload = serde_json::json!({
"type": "script_function_payload",
"function": "0x1::ManagedCoin::mint",
"function": "0x1::managed_coin::mint",
"type_arguments": [format!("0x{}::MoonCoin::MoonCoin", account_owner.address())],
"arguments": [
receiver_address,
Expand Down
4 changes: 2 additions & 2 deletions developer-docs-site/static/examples/typescript/first_coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FirstCoinClient extends RestClient {
async initializeCoin(accountFrom: Account, coinTypeAddress: string): Promise<string> {
let payload: { function: string; arguments: any[]; type: string; type_arguments: any[] } = {
type: "script_function_payload",
function: `0x1::ManagedCoin::initialize`,
function: `0x1::managed_coin::initialize`,
type_arguments: [`0x${coinTypeAddress}::MoonCoin::MoonCoin`],
arguments: [
Buffer.from("Moon Coin", "utf-8").toString("hex"),
Expand Down Expand Up @@ -55,7 +55,7 @@ class FirstCoinClient extends RestClient {
let payload: { function: string; arguments: string[]; type: string; type_arguments: any[] };
payload = {
type: "script_function_payload",
function: `0x1::ManagedCoin::mint`,
function: `0x1::managed_coin::mint`,
type_arguments: [`0x${coinTypeAddress}::MoonCoin::MoonCoin`],
arguments: [receiverAddress, amount.toString()],
};
Expand Down