Skip to content

Commit

Permalink
fix: upgrading to latest sui sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcosulich committed Mar 28, 2023
1 parent 4d13a73 commit b63b3dc
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 154 deletions.
2 changes: 1 addition & 1 deletion components/Burn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Burn = () => {
},
};

const response = await wallet.signAndExecuteTransaction(mintTransaction);
const response = await wallet.signAndExecuteTransactionBlock(mintTransaction);
if (response?.effects?.events) {
const newObjectEvent = response.effects.events.find(
(e) => ('newObject' in e)
Expand Down
40 changes: 18 additions & 22 deletions components/Mint.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
import { useCallback, useEffect, useState } from 'react'
import { ethos, Transaction } from 'ethos-connect'
import { createFactory, useCallback, useEffect, useState } from 'react'
import { ethos, TransactionBlock } from 'ethos-connect'
import { SuccessMessage } from '.';
import { ETHOS_EXAMPLE_CONTRACT } from '../lib/constants';

const Mint = () => {
const { wallet } = ethos.useWallet();
const [nftObjectId, setNftObjectId] = useState(null);
const [nftObjectId, setNftObjectId] = useState<string | undefined>();

const mint = useCallback(async () => {
if (!wallet?.currentAccount) return;

try {
const transaction = new Transaction();
transaction.moveCall({
const transactionBlock = new TransactionBlock();
transactionBlock.moveCall({
target: `${ETHOS_EXAMPLE_CONTRACT}::ethos_example_nft::mint_to_sender`,
arguments: [
transaction.pure("Ethos Example NFT"),
transaction.pure("A sample NFT from Ethos Wallet."),
transaction.pure("https://ethoswallet.xyz/assets/images/ethos-email-logo.png"),
transactionBlock.pure("Ethos Example NFT"),
transactionBlock.pure("A sample NFT from Ethos Wallet."),
transactionBlock.pure("https://ethoswallet.xyz/assets/images/ethos-email-logo.png"),
]
})

const response = await wallet.signAndExecuteTransaction({
transaction,
const response = await wallet.signAndExecuteTransactionBlock({
transactionBlock,
options: {
showInput: true,
showEffects: true,
showEvents: true,
showObjectChanges: true,
}
});
console.log("RESPONSE", response);

if (response?.effects?.events) {
const moveEventEvent = response.effects.events.find(
(e) => ('moveEvent' in e)
if (response?.objectChanges) {
const createdObject = response.objectChanges.find(
(e) => e.type === "created"
);
if (!moveEventEvent || !('moveEvent' in moveEventEvent)) return;

const { moveEvent } = moveEventEvent;
setNftObjectId(moveEvent.fields?.object_id)
if (createdObject && "objectId" in createdObject) {
setNftObjectId(createdObject.objectId)
}
}
} catch (error) {
console.log(error);
}
}, [wallet]);

const reset = useCallback(() => {
setNftObjectId(null)
setNftObjectId(undefined)
}, [])

useEffect(() => {
Expand Down
55 changes: 15 additions & 40 deletions components/Transfer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from 'react'
import { ethos, Transaction } from 'ethos-connect'
import { ethos, TransactionBlock } from 'ethos-connect'
import { SuccessMessage } from '.';
import { ETHOS_EXAMPLE_CONTRACT } from '../lib/constants';

Expand All @@ -11,53 +11,28 @@ const Transfer = () => {
if (!wallet) return;

try {
const mintTransaction = new Transaction();
mintTransaction.moveCall({
const mintTransactionBlock = new TransactionBlock();
const nft = mintTransactionBlock.moveCall({
target: `${ETHOS_EXAMPLE_CONTRACT}::ethos_example_nft::mint_to_sender`,
arguments: [
mintTransaction.pure("Ethos Example NFT"),
mintTransaction.pure("A sample NFT from Ethos Wallet."),
mintTransaction.pure("https://ethoswallet.xyz/assets/images/ethos-email-logo.png")
mintTransactionBlock.pure("Ethos Example NFT"),
mintTransactionBlock.pure("A sample NFT from Ethos Wallet."),
mintTransactionBlock.pure("https://ethoswallet.xyz/assets/images/ethos-email-logo.png")
]
})
mintTransactionBlock.transferObjects(
[nft],
mintTransactionBlock.pure('0x5c48ea29ac876110006a80d036c5454cae3d1ad1')
)

const response = await wallet.signAndExecuteTransaction({
transaction: mintTransaction,
const response = await wallet.signAndExecuteTransactionBlock({
transactionBlock: mintTransactionBlock,
options: {
showInput: true,
showEffects: true,
showEvents: true,
showObjectChanges: true,
}
});
console.log("response", response)

if (response?.effects?.events) {
const moveEventEvent = response.effects.events.find(
(e) => ('moveEvent' in e)
);
if (!moveEventEvent || !('moveEvent' in moveEventEvent)) return;

const { moveEvent } = moveEventEvent;
const objectId = moveEvent.fields?.object_id

const transferTransaction = new Transaction();
transferTransaction.transferObjects(
[transferTransaction.object(objectId)],
transferTransaction.pure('0x5c48ea29ac876110006a80d036c5454cae3d1ad1')
)
transferTransaction.setGasBudget(1000);

const transferResponse = await wallet.signAndExecuteTransaction({
transaction: transferTransaction,
options: {
showInput: true,
showEffects: true,
showEvents: true,
}
});
console.log("transferResponse", transferResponse)
setNftObjectId(objectId);
}

console.log("RESPONSE", response)
} catch (error) {
console.log(error);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const NETWORK = process.env.NETWORK || process.env.NEXT_PUBLIC_NETWORK
export const FAUCET = process.env.FAUCET || process.env.NEXT_PUBLIC_FAUCET
export const ETHOS_EXAMPLE_CONTRACT = "0x8fee24978d8cef4606fd51e9413c2af54476e09aa9e383b5899d533291bbcfcf"
export const ETHOS_EXAMPLE_COIN_TREASURY_CAP = "0xc3270f03a418dd197789e00b14c7fc2d73475ba2b9dc25ad0fb362b4a2adb55f"
export const ETHOS_EXAMPLE_CONTRACT = "0x1cbfdf7de5004f887705fa53bb345d4372e5004bd8b04a6f8868f5e1ca1af9c7"
export const ETHOS_EXAMPLE_COIN_TREASURY_CAP = "0x986b14a24acd0c8bb2b08d166069d6a2361f48e76f34151efc773e5cb98da53b"
export const ETHOS_COIN_TYPE = `${ETHOS_EXAMPLE_CONTRACT}::ethos_example_coin::ETHOS_EXAMPLE_COIN`
108 changes: 75 additions & 33 deletions move/sources/example_nft.move
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module ethos::ethos_example_nft {
use sui::url::{Self, Url};
use std::string;
use std::string::{utf8, String};
use sui::object::{Self, ID, UID};
use sui::event;
use sui::transfer;
use sui::tx_context::{Self, TxContext};
use sui::transfer::{public_transfer};
use sui::tx_context::{sender, Self, TxContext};

use sui::package;
use sui::display;

/// An example NFT that can be minted by anybody
struct EthosNFT has key, store {
id: UID,
/// Name for the token
name: string::String,
/// Description of the token
description: string::String,
/// URL for the token
name: String,
description: String,
url: Url,
// TODO: allow custom attributes
}

/// One-Time-Witness for the module.
struct ETHOS_EXAMPLE_NFT has drop {}

// ===== Events =====

struct NFTMinted has copy, drop {
Expand All @@ -29,18 +27,18 @@ module ethos::ethos_example_nft {
// The creator of the NFT
creator: address,
// The name of the NFT
name: string::String,
name: String,
}

// ===== Public view functions =====

/// Get the NFT's `name`
public fun name(nft: &EthosNFT): &string::String {
public fun name(nft: &EthosNFT): &String {
&nft.name
}

/// Get the NFT's `description`
public fun description(nft: &EthosNFT): &string::String {
public fun description(nft: &EthosNFT): &String {
&nft.description
}

Expand All @@ -49,6 +47,38 @@ module ethos::ethos_example_nft {
&nft.url
}

fun init(otw: ETHOS_EXAMPLE_NFT, ctx: &mut TxContext) {
let keys = vector[
utf8(b"name"),
utf8(b"image_url"),
utf8(b"description"),
utf8(b"project_url"),
utf8(b"creator"),
];

let values = vector[
utf8(b"{name}"),
utf8(b"{url}"),
utf8(b"{description}"),
utf8(b"https://ethos-example-app.onrender.com/"),
utf8(b"Ethos")
];

// Claim the `Publisher` for the package!
let publisher = package::claim(otw, ctx);

// Get a new `Display` object for the `Hero` type.
let display = display::new_with_fields<EthosNFT>(
&publisher, keys, values, ctx
);

// Commit first version of `Display` to apply changes.
display::update_version(&mut display);

public_transfer(publisher, sender(ctx));
public_transfer(display, sender(ctx));
}

// ===== Entrypoints =====

/// Create a new ethos nft
Expand All @@ -58,28 +88,16 @@ module ethos::ethos_example_nft {
url: vector<u8>,
ctx: &mut TxContext
) {
let sender = tx_context::sender(ctx);
let nft = EthosNFT {
id: object::new(ctx),
name: string::utf8(name),
description: string::utf8(description),
url: url::new_unsafe_from_bytes(url)
};

event::emit(NFTMinted {
object_id: object::id(&nft),
creator: sender,
name: nft.name,
});

transfer::public_transfer(nft, sender);
let sender = sender(ctx);
let nft = mint(name, description, url, ctx);
public_transfer(nft, sender);
}

/// Transfer `nft` to `recipient`
public entry fun transfer(
nft: EthosNFT, recipient: address, _: &mut TxContext
) {
transfer::public_transfer(nft, recipient)
public_transfer(nft, recipient)
}

/// Update the `description` of `nft` to `new_description`
Expand All @@ -88,12 +106,36 @@ module ethos::ethos_example_nft {
new_description: vector<u8>,
_: &mut TxContext
) {
nft.description = string::utf8(new_description)
nft.description = utf8(new_description)
}

/// Permanently delete `nft`
public entry fun burn(nft: EthosNFT, _: &mut TxContext) {
let EthosNFT { id, name: _, description: _, url: _ } = nft;
object::delete(id)
}

public fun mint(
name: vector<u8>,
description: vector<u8>,
url: vector<u8>,
ctx: &mut TxContext
): EthosNFT {
let sender = tx_context::sender(ctx);

let nft = EthosNFT {
id: object::new(ctx),
name: utf8(name),
description: utf8(description),
url: url::new_unsafe_from_bytes(url)
};

event::emit(NFTMinted {
object_id: object::id(&nft),
creator: sender,
name: nft.name,
});

nft
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@heroicons/react": "^1.0.6",
"ethos-connect": "0.0.105-beta.5",
"ethos-connect": "0.0.107",
"next": "12.2.4",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
Loading

0 comments on commit b63b3dc

Please sign in to comment.