Skip to content

Commit

Permalink
Starknet example use useExplorer
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Apr 11, 2024
1 parent 9945851 commit d2ea225
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { useAccount, useContractWrite } from "@starknet-react/core";
import {
useAccount,
useContractWrite,
useExplorer,
} from "@starknet-react/core";
import { useEffect, useState } from "react";

const worldAddress =
Expand All @@ -8,6 +12,7 @@ const actionsAddress =

export function DojoSpawnAndMove() {
const { account } = useAccount();
const explorer = useExplorer();
const [txnHash, setTxnHash] = useState<string>();
const { writeAsync: spawn } = useContractWrite({
calls: [
Expand Down Expand Up @@ -60,7 +65,7 @@ export function DojoSpawnAndMove() {
<p>
Transaction hash:{" "}
<a
href={`https://sepolia.starkscan.io/tx/${txnHash}`}
href={explorer.transaction(txnHash)}
target="_blank"
rel="noreferrer"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sepolia } from "@starknet-react/chains";
import { Connector, StarknetConfig } from "@starknet-react/core";
import { Connector, StarknetConfig, starkscan } from "@starknet-react/core";
import { PropsWithChildren } from "react";
import CartridgeConnector from "@cartridge/connector";
import { RpcProvider } from "starknet";
Expand All @@ -10,6 +10,7 @@ export function StarknetProvider({ children }: PropsWithChildren) {
autoConnect
chains={[sepolia]}
connectors={connectors}
explorer={starkscan}
provider={(_chain) =>
new RpcProvider({
nodeUrl: process.env.NEXT_PUBLIC_RPC_SEPOLIA,
Expand All @@ -20,8 +21,7 @@ export function StarknetProvider({ children }: PropsWithChildren) {
</StarknetConfig>
);
}
console.log(process.env.NEXT_PUBLIC_VERCEL_ENV);
console.log(process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL);

const url =
process.env.NEXT_PUBLIC_VERCEL_ENV === "preview"
? `https://keychain-git-${process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF}.preview.cartridge.gg`
Expand Down
5 changes: 3 additions & 2 deletions examples/starknet-react-next/src/components/TransferEth.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAccount } from "@starknet-react/core";
import { useAccount, useExplorer } from "@starknet-react/core";
import { useCallback, useState } from "react";
import { constants } from "starknet";

Expand All @@ -10,6 +10,7 @@ export const TransferEth = () => {
constants.StarknetChainId.SN_SEPOLIA,
);
const { account } = useAccount();
const explorer = useExplorer();
const [txnHash, setTxnHash] = useState<string>();

const executePointOne = useCallback(async () => {
Expand Down Expand Up @@ -135,7 +136,7 @@ export const TransferEth = () => {
<p>
Transaction hash:{" "}
<a
href={`https://sepolia.starkscan.io/tx/${txnHash}`}
href={explorer.transaction(txnHash)}
target="_blank"
rel="noreferrer"
>
Expand Down

0 comments on commit d2ea225

Please sign in to comment.