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

Redeploy contract under object #60

Merged
merged 2 commits into from
Apr 30, 2024
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
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ We introduce the following concepts:

This dApp will be used as an educational demo hosted on [Aptos Learn](https://learn.aptoslabs.com/).

You can find more instructions about the Move contract in move/README.md.

---

This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
Expand All @@ -21,10 +23,7 @@ This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next
First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
cd frontend
pnpm dev
```

Expand Down
1 change: 0 additions & 1 deletion frontend/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
NEXT_PUBLIC_CONTRACT_ADDRESS="0xa3527451930153f0da31da246da3837c5c6ee3156389a075af4bf6465c91aef1"
NEXT_PUBLIC_BODY_OPTIONS=5
NEXT_PUBLIC_EAR_OPTIONS=6
NEXT_PUBLIC_FACE_OPTIONS=4
Expand Down
9 changes: 9 additions & 0 deletions frontend/gen_abi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash

NETWORK=testnet

CONTRACT_ADDRESS=$(cat ../move/contract_address.txt)

PACKAGE_NAME=$(cat ../move/sources/$(ls ../move/sources/ | head -n 1) | head -n 1 | sed -n 's/module [^:]*::\(.*\) {/\1/p')

echo "export const ABI = $(curl https://fullnode.$NETWORK.aptoslabs.com/v1/accounts/$CONTRACT_ADDRESS/module/$PACKAGE_NAME | sed -n 's/.*"abi":\({.*}\).*}$/\1/p') as const" > src/utils/abi.ts
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"aptos": "aptos"
"aptos": "aptos",
"gen-abi": "./gen_abi.sh"
},
"dependencies": {
"@aptos-labs/ts-sdk": "^1.5.1",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/home/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useState, useEffect, useCallback } from "react";
import { Pet } from "./Pet";
import { useWallet } from "@aptos-labs/wallet-adapter-react";
import { Mint } from "./Mint";
import { NEXT_PUBLIC_CONTRACT_ADDRESS } from "@/utils/env";
import { getAptosClient } from "@/utils/aptosClient";
import { Modal } from "@/components/Modal";
import { ABI } from "@/utils/abi";

const TESTNET_ID = "2";

Expand All @@ -21,14 +21,14 @@ export function Connected() {

const [hasPet] = await aptosClient.view({
payload: {
function: `${NEXT_PUBLIC_CONTRACT_ADDRESS}::main::has_aptogotchi`,
function: `${ABI.address}::main::has_aptogotchi`,
functionArguments: [account.address],
},
});
if (hasPet as boolean) {
const response = await aptosClient.view({
payload: {
function: `${NEXT_PUBLIC_CONTRACT_ADDRESS}::main::get_aptogotchi`,
function: `${ABI.address}::main::get_aptogotchi`,
functionArguments: [account.address],
},
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/home/Mint/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useState } from "react";
import { useWallet } from "@aptos-labs/wallet-adapter-react";
import { NEXT_PUBLIC_CONTRACT_ADDRESS } from "@/utils/env";
import { getAptosClient } from "@/utils/aptosClient";
import { ShufflePetImage } from "@/app/home/Pet/ShufflePetImage";
import { DEFAULT_PET, PetParts } from "@/app/home/Pet";
import { ABI } from "@/utils/abi";

const aptosClient = getAptosClient();

Expand All @@ -28,7 +28,7 @@ export function Mint({ fetchPet }: MintProps) {
const response = await signAndSubmitTransaction({
sender: account.address,
data: {
function: `${NEXT_PUBLIC_CONTRACT_ADDRESS}::main::create_aptogotchi`,
function: `${ABI.address}::main::create_aptogotchi`,
typeArguments: [],
functionArguments: [
newName,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/home/Pet/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { useWallet } from "@aptos-labs/wallet-adapter-react";
import { Pet } from ".";
import { getAptosClient } from "@/utils/aptosClient";
import {
NEXT_PUBLIC_CONTRACT_ADDRESS,
NEXT_PUBLIC_ENERGY_CAP,
NEXT_PUBLIC_ENERGY_DECREASE,
NEXT_PUBLIC_ENERGY_INCREASE,
} from "@/utils/env";
import { ABI } from "@/utils/abi";

const aptosClient = getAptosClient();

Expand Down Expand Up @@ -52,7 +52,7 @@ export function Actions({
const response = await signAndSubmitTransaction({
sender: account.address,
data: {
function: `${NEXT_PUBLIC_CONTRACT_ADDRESS}::main::feed`,
function: `${ABI.address}::main::feed`,
typeArguments: [],
functionArguments: [NEXT_PUBLIC_ENERGY_INCREASE],
},
Expand Down Expand Up @@ -89,7 +89,7 @@ export function Actions({
const response = await signAndSubmitTransaction({
sender: account.address,
data: {
function: `${NEXT_PUBLIC_CONTRACT_ADDRESS}::main::play`,
function: `${ABI.address}::main::play`,
typeArguments: [],
functionArguments: [NEXT_PUBLIC_ENERGY_DECREASE],
},
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/home/Pet/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { HealthBar } from "@/components/HealthBar";
import { Pet } from ".";
import { Dispatch, SetStateAction, useState } from "react";
import { useWallet } from "@aptos-labs/wallet-adapter-react";
import { NEXT_PUBLIC_CONTRACT_ADDRESS } from "@/utils/env";
import { getAptosClient } from "@/utils/aptosClient";
import { ABI } from "@/utils/abi";

export interface PetDetailsProps {
pet: Pet;
Expand All @@ -32,10 +32,10 @@ export function PetDetails({ pet, setPet }: PetDetailsProps) {
const response = await signAndSubmitTransaction({
sender: account.address,
data: {
function: `${NEXT_PUBLIC_CONTRACT_ADDRESS}::main::set_name`,
function: `${ABI.address}::main::set_name`,
typeArguments: [],
functionArguments: [newName],
}
},
});
await aptosClient.waitForTransaction({ transactionHash: response.hash });

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/hooks/useGetAptogotchiCollection.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useCallback, useState } from "react";
import { useWallet } from "@aptos-labs/wallet-adapter-react";
import { getAptosClient } from "@/utils/aptosClient";
import { NEXT_PUBLIC_CONTRACT_ADDRESS } from "@/utils/env";
import { queryAptogotchiCollection } from "@/graphql/queryAptogotchiCollection";
import { padAddressIfNeeded } from "@/utils/address";
import { ABI } from "@/utils/abi";

const aptosClient = getAptosClient();

Expand Down Expand Up @@ -39,7 +39,7 @@ export function useGetAptogotchiCollection() {

const aptogotchiCollectionAddressResponse = (await aptosClient.view({
payload: {
function: `${NEXT_PUBLIC_CONTRACT_ADDRESS}::main::get_aptogotchi_collection_address`,
function: `${ABI.address}::main::get_aptogotchi_collection_address`,
},
})) as [`0x${string}`];

Expand All @@ -65,7 +65,7 @@ export function useGetAptogotchiCollection() {
.map((holder) =>
aptosClient.view({
payload: {
function: `${NEXT_PUBLIC_CONTRACT_ADDRESS}::main::get_aptogotchi`,
function: `${ABI.address}::main::get_aptogotchi`,
functionArguments: [holder.owner_address],
},
})
Expand Down
144 changes: 144 additions & 0 deletions frontend/src/utils/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
export const ABI = {
address: "0xb686acdc6c166f92aa2090f005acc275b258c5d91653df9b3b8af21e7c104773",
name: "main",
friends: [],
exposed_functions: [
{
name: "create_aptogotchi",
visibility: "public",
is_entry: true,
is_view: false,
generic_type_params: [],
params: ["&signer", "0x1::string::String", "u8", "u8", "u8"],
return: [],
},
{
name: "feed",
visibility: "public",
is_entry: true,
is_view: false,
generic_type_params: [],
params: ["&signer", "u64"],
return: [],
},
{
name: "get_aptogotchi",
visibility: "public",
is_entry: false,
is_view: true,
generic_type_params: [],
params: ["address"],
return: [
"0x1::string::String",
"u64",
"u64",
"0xb686acdc6c166f92aa2090f005acc275b258c5d91653df9b3b8af21e7c104773::main::AptogotchiParts",
],
},
{
name: "get_aptogotchi_address",
visibility: "public",
is_entry: false,
is_view: true,
generic_type_params: [],
params: ["address"],
return: ["address"],
},
{
name: "get_aptogotchi_collection_address",
visibility: "public",
is_entry: false,
is_view: true,
generic_type_params: [],
params: [],
return: ["address"],
},
{
name: "has_aptogotchi",
visibility: "public",
is_entry: false,
is_view: true,
generic_type_params: [],
params: ["address"],
return: ["bool"],
},
{
name: "play",
visibility: "public",
is_entry: true,
is_view: false,
generic_type_params: [],
params: ["&signer", "u64"],
return: [],
},
{
name: "set_name",
visibility: "public",
is_entry: true,
is_view: false,
generic_type_params: [],
params: ["signer", "0x1::string::String"],
return: [],
},
{
name: "set_parts",
visibility: "public",
is_entry: true,
is_view: false,
generic_type_params: [],
params: ["&signer", "u8", "u8", "u8"],
return: [],
},
],
structs: [
{
name: "Aptogotchi",
is_native: false,
abilities: ["key"],
generic_type_params: [],
fields: [
{ name: "name", type: "0x1::string::String" },
{ name: "birthday", type: "u64" },
{ name: "energy_points", type: "u64" },
{
name: "parts",
type: "0xb686acdc6c166f92aa2090f005acc275b258c5d91653df9b3b8af21e7c104773::main::AptogotchiParts",
},
{ name: "mutator_ref", type: "0x4::token::MutatorRef" },
{ name: "burn_ref", type: "0x4::token::BurnRef" },
],
},
{
name: "AptogotchiParts",
is_native: false,
abilities: ["copy", "drop", "store", "key"],
generic_type_params: [],
fields: [
{ name: "body", type: "u8" },
{ name: "ear", type: "u8" },
{ name: "face", type: "u8" },
],
},
{
name: "MintAptogotchiEvent",
is_native: false,
abilities: ["drop", "store"],
generic_type_params: [],
fields: [
{ name: "token_name", type: "0x1::string::String" },
{ name: "aptogotchi_name", type: "0x1::string::String" },
{
name: "parts",
type: "0xb686acdc6c166f92aa2090f005acc275b258c5d91653df9b3b8af21e7c104773::main::AptogotchiParts",
},
],
},
{
name: "ObjectController",
is_native: false,
abilities: ["key"],
generic_type_params: [],
fields: [{ name: "app_extend_ref", type: "0x1::object::ExtendRef" }],
},
],
} as const;
2 changes: 0 additions & 2 deletions frontend/src/utils/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const NEXT_PUBLIC_CONTRACT_ADDRESS = process.env
.NEXT_PUBLIC_CONTRACT_ADDRESS as `0x${string}`;
export const NEXT_PUBLIC_BODY_OPTIONS = process.env.NEXT_PUBLIC_BODY_OPTIONS;
export const NEXT_PUBLIC_EAR_OPTIONS = process.env.NEXT_PUBLIC_EAR_OPTIONS;
export const NEXT_PUBLIC_FACE_OPTIONS = process.env.NEXT_PUBLIC_FACE_OPTIONS;
Expand Down
4 changes: 2 additions & 2 deletions move/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ version = "1.0.0"
upgrade_policy = "compatible"

[addresses]
aptogotchi = "_"
aptogotchi_addr = "_"

[dependencies]
AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "main", subdir = "aptos-move/framework/aptos-framework"}
AptosTokenObjects = {git = "https://github.com/aptos-labs/aptos-core.git", rev = "main", subdir = "aptos-move/framework/aptos-token-objects"}

# For use when developing and testing this module
[dev-addresses]
aptogotchi = "0x100"
aptogotchi_addr = "0x100"
18 changes: 16 additions & 2 deletions move/README.MD
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
# Aptogotchi

## Publish Modules
## Publish and Upgrade Module

```shell
# publish module
./sh_scripts/move_publish.sh
```

After publishing, go to frontend directory to re-generate the ABI.

```shell
cd ../frontend
pnpm generate
```

Upgrade published module, this only works when you don't have breaking change.
If you have breaking change, you need to publish to a new address.
```shell
./sh_scripts/move_upgrade.sh
```

## Run unit tests

```shell
./sh_scripts/move_test.sh
```

## Run move scripts
## Run Move scripts

Create gotchi.
```shell
Expand Down
1 change: 1 addition & 0 deletions move/contract_address.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xb686acdc6c166f92aa2090f005acc275b258c5d91653df9b3b8af21e7c104773
2 changes: 1 addition & 1 deletion move/scripts/script_create_gotchi.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ script {

fun create_gotchi(user: &signer) {
let gotchi_name = utf8(b"gotchi");
aptogotchi::main::create_aptogotchi(user, gotchi_name, 1, 1, 1);
aptogotchi_addr::main::create_aptogotchi(user, gotchi_name, 1, 1, 1);
}
}
4 changes: 2 additions & 2 deletions move/scripts/script_feed_gotchi.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ script {
// Increasing gotchi's energy point by 2.
fun feed_gotchi(user: &signer) {
let energy_points = 1;
aptogotchi::main::feed(user, energy_points);
aptogotchi::main::feed(user, energy_points);
aptogotchi_addr::main::feed(user, energy_points);
aptogotchi_addr::main::feed(user, energy_points);
}
}
Loading
Loading