Skip to content

Commit

Permalink
Merge pull request #100 from Scaffold-Stark/update
Browse files Browse the repository at this point in the history
Minor bug fixes and improvements.
  • Loading branch information
metalboyrick authored Feb 4, 2025
2 parents 199c82a + 193f25a commit 8017a63
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 52 deletions.
87 changes: 57 additions & 30 deletions docs/deploying/deploy-smart-contracts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,43 @@ To deploy your smart contracts to a live network, there are a few things you nee

## 1. Configure your network

Scaffold-Stark 2 comes with a selection of predefined networks. They are `Devnet` and `Sepolia`.
Scaffold-Stark 2 comes with a selection of predefined networks: `Devnet`, `Sepolia`, and `Mainnet`.

Here are the [Starknet docs](https://docs.starknet.io/documentation/tools/api-services/) for information on Seplia networks providers.
Here are the [Starknet docs](https://docs.starknet.io/documentation/tools/api-services/) for information on Sepolia network providers.

## 2. Use pre-funded accounts and add one of them to deploy the contract(s) from.

The deployer account is the account that will deploy your contracts. Additionally, the deployer account will be used to execute any function calls that are part of your deployment script.

You can use any pre-funded account / private key or add your crypto wallet's private key.

You can also manually set your own private key, you will need to add `PRIVATE_KEY_SEPOLIA=yourWalletPrivateKey` to the `packages/snfoundry/.env` file.
### Configure Sepolia:

To use the Sepolia, set your own private key and configure the necessary environment variables by adding and replacing `yourWalletPrivateKey`, `yourWalletAddress` in the following:

Add the following to the `packages/snfoundry/.env` file:

If you are working with Sepolia, you need to use the setup:

```env
PRIVATE_KEY_SEPOLIA=yourWalletPrivateKey
RPC_URL_SEPOLIA=https://starknet-sepolia.public.blastapi.io/rpc/v0_7
ACCOUNT_ADDRESS_SEPOLIA=yourWalletAddress
```

### Configure Mainnet:

To use the Mainnet, set your own private key and configure the necessary environment variables by adding and replacing `yourWalletPrivateKey`, `yourWalletAddress` in the following:

Add the following to the `packages/snfoundry/.env` file:

If you are working with Mainnet, you need to use the setup:

```env
PRIVATE_KEY_MAINNET=yourWalletPrivateKey
RPC_URL_MAINNET=https://starknet-mainnet.public.blastapi.io/rpc/v0_7
ACCOUNT_ADDRESS_MAINNET=yourWalletAddress
```

## 3. Changing the smart contract name

Expand All @@ -27,45 +53,46 @@ If you decide to rename the default `YourContract` Cairo contract to something e
### Steps to Change the Contract Name:

- **Rename the Cairo Contract**:
- Rename the `.cairo` file in the `contracts` directory to the desired name. For example, if you rename `YourContract.cairo` to `MyNewContract.cairo`, make sure the new `.cairo` file exists in the `contracts` folder.

- **Update the `deploy.ts` Script**:
- After renaming the Cairo contract file, open the `deploy.ts` script and change the contract name from `YourContract` to the new contract name you’ve chosen. The relevant section in the `deploy.ts` file will look like this:

```typescript
const deployScript = async (): Promise<void> => {
await deployContract({
contract: "MyNewContract", // Change this to your renamed contract
constructorArgs: {
owner: deployer.address,
},
});
};
```
Rename the `.cairo` file in the `contracts` directory to the desired name. For example, if you rename `YourContract.cairo` to `MyNewContract.cairo`, make sure the new `.cairo` file exists in the `contracts` folder.

- **(Optional) Deploy the same contract under a different name**
- **Update the `deploy.ts` Script**:

If you want to deploy the same contract but reference it under a different name , you can use `contractName`:
After renaming the Cairo contract file, open the `deploy.ts` script and change the contract name from `YourContract` to the new contract name you’ve chosen. The relevant section in the `deploy.ts` file will look like this:

```typescript
```typescript
const deployScript = async (): Promise<void> => {
await deployContract({
contract: "MyNewContract",
contractName: "CustomDisplayName", // Allows multiple deployments with unique references
contract: "MyNewContract", // Change this to your renamed contract
constructorArgs: {
owner: deployer.address,
},
});
```
};
```

- **(Optional) Deploy the same contract under a different name**:

This can be useful if you want to:
If you want to deploy the same contract but reference it under a different name, you can use `contractName`:

- Deploy multiple instances of the same contract with different identifiers.
```typescript
await deployContract({
contract: "MyNewContract",
contractName: "CustomDisplayName", // Allows multiple deployments with unique references
constructorArgs: {
owner: deployer.address,
},
});
```

- Reference the deployed contract under a custom name for clarity in deployment logs.
This can be useful if you want to:

- Deploy multiple instances of the same contract with different identifiers.
- Reference the deployed contract under a custom name for clarity in deployment logs.

## 4. Deploy your smart contract(s)

By default `yarn deploy` will deploy contract to the local network. You can change `defaultNetwork` in `scaffold.config.ts`
By default, `yarn deploy` will deploy the contract to the local network. You can change `defaultNetwork` in `scaffold.config.ts`.

Run the command below to deploy the smart contract to the target network. Make sure to have some funds in your deployer account to pay for the transaction.

Expand All @@ -75,7 +102,7 @@ yarn deploy --network <NETWORK_NAME>

e.g. `yarn deploy --network sepolia`

## Configuration of Third-Party Services for Production-Grade Apps.
## Configuration of Third-Party Services for Production-Grade Apps

By default, Scaffold-Stark 2 provides predefined API keys for popular services such as Infura. This allows you to begin developing and testing your applications more easily, avoiding the need to register for this service.

Expand All @@ -84,5 +111,5 @@ For production-grade applications, it's recommended to obtain your own API keys
- `RPC_URL_SEPOLIA` variable in `packages/snfoundry/.env` and `packages/nextjs/.env.local`. You can create API keys from the [Alchemy dashboard](https://dashboard.alchemy.com/).

:::tip Hint
It's recommended to store environment variables for nextjs in vercel/system env config for live apps and use `.env.local` for local testing.
:::tip Hint
It's recommended to store environment variables for Next.js in Vercel/system environment variable configuration for live apps and use `.env.local` for local testing.
:::
23 changes: 11 additions & 12 deletions docs/hooks/useScaffoldEthBalance.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@ sidebar_position: 9

Use this hook to read the Ethereum (ETH) balance of a specified address on the StarkNet blockchain.

```ts
const { value, formatted, symbol } = useScaffoldEthBalance({
address: "0x01176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
});
```

This example retrieves the ETH balance for the specified address using the deployed Ethereum contract on StarkNet. The returned object includes the raw balance value, the formatted balance, and the ETH symbol.

## Usage Example

```tsx
const BalanceDisplay = ({ userAddress }) => {
const { formatted, symbol } = useScaffoldEthBalance({ address: userAddress });
import useScaffoldEthBalance from "~~/hooks/scaffold-stark/useScaffoldEthBalance";
import { useAccount } from "~~/hooks/useAccount";

function EthBalanceDisplay() {
const { address } = useAccount();
const { value, formatted, symbol } = useScaffoldEthBalance({ address: address || "" });

return (
<div>
<p>
Balance: {formatted} {symbol}
</p>
<h3>ETH Balance:</h3>
<p>Raw Value: {value ? value.toString() : ""}</p>
<p>Formatted: {formatted}</p>
<p>Symbol: {symbol}</p>
</div>
);
};
}
```

This example demonstrates how to use the `useScaffoldEthBalance` hook to display the formatted ETH balance for a user's address.
Expand Down
12 changes: 6 additions & 6 deletions docs/hooks/useScaffoldStrkBalance.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ The `useScaffoldStrkBalance` hook is a custom React hook designed to fetch and d
## Usage Example

```ts
import useScaffoldStrkBalance from './hooks/useScaffoldStrkBalance';
import useScaffoldStrkBalance from '~~/hooks/scaffold-stark/useScaffoldStrkBalance';
import { useAccount } from '~~/hooks/useAccount';

const address = "0x01176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"

function StrkBalanceDisplay({ address }) {
const { value, formatted, symbol } = useScaffoldStrkBalance({ address: "0x01176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8" });
function StrkBalanceDisplay() {
const { address } = useAccount();
const { value, formatted, symbol } = useScaffoldStrkBalance({ address: address || "" });

return (
<div>
<h3>STRK Balance:</h3>
<p>Raw Value: {value}</p>
<p>Raw Value: {value ? value.toString() : ""}</p>
<p>Formatted: {formatted}</p>
<p>Symbol: {symbol}</p>
</div>
Expand Down
8 changes: 4 additions & 4 deletions docs/quick-start/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Once you have `asdf` installed locally, you can download Scarb plugin with the f
asdf plugin add scarb
```

This will allow you to download specific versions. You can choose the same version as the Dojo's Cairo version, for example, 2.6.5, with the following command:
This will allow you to download specific versions. You can choose the same version as the Cairo's version, for example, 2.9.2, with the following command:

```bash
asdf install scarb 2.9.2
Expand Down Expand Up @@ -129,10 +129,10 @@ snforge --version
<details>
<summary><b>Starknet Foundry Installation Process</b></summary>

To install Starknet Foundry, please refer to the [installation instructions](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html#installation-via-asdf).
We strongly recommend that you install Scarb via [asdf](https://docs.swmansion.com/scarb/download.html#install-via-asdf).
To install Starknet Foundry, please refer to the [installation instructions](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html#installation).
We strongly recommend that you install Starknet Foundry via [asdf](https://foundry-rs.github.io/starknet-foundry/getting-started/installation.html#installation-via-asdf).

Once you have `asdf` installed locally, you can download Scarb plugin with the following command:
Once you have `asdf` installed locally, you can download Starknet Foundry plugin with the following command:

```bash
asdf plugin add starknet-foundry
Expand Down

0 comments on commit 8017a63

Please sign in to comment.