Skip to content

Commit

Permalink
minor changes, add live endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
george-hub331 committed Jun 23, 2024
1 parent ba53763 commit d8ee536
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
48 changes: 36 additions & 12 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { displayTxResult } from "./debug/_components/contract";
import BigNumber from "bignumber.js";

const Home: NextPage = () => {

const connectedAddress = useAccount();

const [isModalOpen, setIsModalOpen] = useState(false);
Expand All @@ -41,7 +42,7 @@ const Home: NextPage = () => {

const [nftSymbol, setNftSymbol] = useState("");

const base = "http://localhost:3300/";
const base = "https://starkai.cryptea.me/";

const deployContract = async () => {
if (isLoading) return;
Expand All @@ -65,13 +66,16 @@ const Home: NextPage = () => {
// return;

try {

const res = await axios.post(`${base}create`, {
name: nftName,
desc: nftDesc,
});

const image = `https://gateway.pinata.cloud/ipfs/${res.data.hash}?1`;

console.log(image, "sss");

setImage(image);

// 0x0758e5854628069e27bc547b75c1a5aa8e24a5fccace22984183fa08199871a2
Expand All @@ -84,6 +88,8 @@ const Home: NextPage = () => {
base_uri: image,
});

console.log(constructorCalldata, "sss");

const classDeploy = await connectedAddress.account?.deploy({
classHash:
"0x07d2fa6fb834a03ccab365379ff25b0f9b91f0eea9be115cd216f01a430e913c",
Expand All @@ -105,6 +111,10 @@ const Home: NextPage = () => {

console.log(mres, "sss");

toast.success(
`NFT deployed successfully 🎉 \n hash - ${classDeploy.transaction_hash}`
);

setIsModalOpen(false);
setSuccess(true);
}
Expand Down Expand Up @@ -133,7 +143,7 @@ const Home: NextPage = () => {
console.log(res, "contract");

await axios.post(`${base}ondeploy`, {
address: connectedAddress.address,
address,
contract: cnt,
desc: nftDesc,
});
Expand All @@ -144,7 +154,7 @@ const Home: NextPage = () => {

setAddress("");

toast.success("NFT minted to address successfully");
toast.success(`NFT minted to address successfully \n hash - ${res.transaction_hash}`);

} catch (error) {
toast.dismiss(ee);
Expand All @@ -161,12 +171,9 @@ const Home: NextPage = () => {
const [nftDx, setNftDx] = useState<any>([]);

function feltToString(felt: any) {
let hexStr = felt.toString(16);
if (hexStr.length % 2 !== 0) {
hexStr = "0" + hexStr;
}
const hexStr = felt.toString(16);
const bytes = Buffer.from(hexStr, "hex");
return bytes.toString("utf-8");
return bytes.toString("utf-8").replace(/\0/g, ""); // Remove padding null characters
}

useEffect(() => {
Expand Down Expand Up @@ -197,19 +204,24 @@ const Home: NextPage = () => {
function feltToNumber(felt: any) {
return new BigNumber(felt.toString()).toNumber();
}


return {
...e,
uri: feltToString(uri.data[0]),
uri: displayTxResult(uri, false, [
{ type: "core::byte_array::ByteArray" },
]),
symbol: feltToString(symbol.pending_word),
name: feltToString(name.pending_word),
};
})
);

console.log(dx, 'dd')

setNfts(dx);

setPageLoader(false);
if (connectedAddress.address) setPageLoader(false);

} catch (error) {
console.log(error);
Expand All @@ -223,7 +235,15 @@ const Home: NextPage = () => {
className={`w-[60vw] mx-auto md:max-h-[30rem] md:max-w-[45rem]`}
isOpen={success}
animate={true}
onClose={() => {}}
onClose={() => {
setSuccess(false);
setNftDesc("");
setImage("");
setAddress("");
setContract("");
setNftName("");
window.location.reload();
}}
>
<div className="p-7 w-full">
<div className="">
Expand All @@ -240,6 +260,7 @@ const Home: NextPage = () => {
setAddress("");
setContract("");
setNftName("");
window.location.reload();
}}
>
Close
Expand Down Expand Up @@ -410,6 +431,9 @@ const Home: NextPage = () => {
>
{/* show a list of nfts */}
{nfts.map((e: any, i: number) => {

console.log(e.url, 'from map')

return (
<div
onClick={() => {}}
Expand All @@ -418,7 +442,7 @@ const Home: NextPage = () => {
>
<div className="w-[150px] h-[150px] bg-gray-200 rounded-full mb-5">
<Image
src={`${e.uri}`}
src={e.uri}
width={150}
height={150}
alt="nft"
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const deployedContracts = {
devnet: {
StarkNFT: {
address:
"0x0211866c7b38180ec0031aa59fb0b5747ffd9e4ec8293e383278e111d57081a8",
"0x02a48b013360c63875ae4a43bde1edb2beeb64139344782138b78c3be3e23c20",
abi: [
{
type: "impl",
Expand Down
Binary file added packages/nodejs/public/1719144829231.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/snfoundry/scripts-ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const deployScript = async (): Promise<void> => {
recipient: deployer.address, // the deployer address is the owner of the contract
name: "StarkNFT",
symbol: "SNFT",
base_uri: "https://gateway.pinata.cloud/ipfs/",
base_uri:
"https://gateway.pinata.cloud/ipfs/QmZqALrmo8S6xw1fz9Xr9GrNM896enrxBHDYricBRECxFE?1",
},
"StarkNFT"
);
Expand Down

0 comments on commit d8ee536

Please sign in to comment.