Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Tooling section: General update (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
gianalarcon authored Jan 26, 2024
1 parent 2ab0cf0 commit 08cfe2d
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 144 deletions.
3 changes: 3 additions & 0 deletions examples/Ownable-Starknet/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export STARKNET_ACCOUNT=/home/gianm/.starkli-wallets/deployer/my_account_argent.json
export STARKNET_KEYSTORE=/home/gianm/.starkli-wallets/deployer/my_keystore_argent.json
export STARKNET_RPC=https://starknet-testnet.public.blastapi.io/rpc/v0_6 # you can keep this rpc url unchanged
8 changes: 0 additions & 8 deletions examples/Ownable-Starknet/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,3 @@ version = 1
[[package]]
name = "ownable_starknet"
version = "0.1.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "snforge_std"
version = "0.1.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.7.1#d1bd8b9a361d437e8eaeb4ebffac291a48b4c920"
3 changes: 1 addition & 2 deletions examples/Ownable-Starknet/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ version = "0.1.0"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.7.1" } #v0.7.0
starknet = ">=2.2.0"
starknet = ">=2.5.0"

[[target.starknet-contract]]
sierra = true
Expand Down
1 change: 0 additions & 1 deletion examples/Ownable-Starknet/data/calldata.txt

This file was deleted.

32 changes: 28 additions & 4 deletions examples/Ownable-Starknet/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ mod ownable {
}

#[constructor]
fn constructor(ref self: ContractState, initial_owner: ContractAddress,) {
fn constructor(ref self: ContractState, initial_owner: ContractAddress) {
self.owner.write(initial_owner);
self.data.write(1);
// Any variable of the storage that is not initialized
// will have default value -> data = 0.
}

#[external(v0)]
#[abi(embed_v0)]
impl OwnableDataImpl of IData<ContractState> {
fn other_func(self: @ContractState, other_contract: ContractAddress) -> felt252 {
IDataDispatcher { contract_address: other_contract }.get_data()
Expand All @@ -63,14 +63,14 @@ mod ownable {
}
}

#[external(v0)]
#[abi(embed_v0)]
impl OwnableTraitImpl of OwnableTrait<ContractState> {
fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) {
self.only_owner();
let prev_owner = self.owner.read();
self.owner.write(new_owner);

self.emit(OwnershipTransferred { prev_owner, new_owner, });
self.emit(OwnershipTransferred { prev_owner, new_owner });
}

fn owner(self: @ContractState) -> ContractAddress {
Expand All @@ -87,3 +87,27 @@ mod ownable {
}
}

#[cfg(test)]
mod tests {
use ownable_starknet::ownable;
use ownable_starknet::{OwnableTraitDispatcher, OwnableTraitDispatcherTrait};
use starknet::{ContractAddress, Into, TryInto, OptionTrait};
use starknet::syscalls::deploy_syscall;
use result::ResultTrait;
use array::{ArrayTrait, SpanTrait};

#[test]
#[available_gas(10_000_000)]
fn unit_test() {
let admin_address: ContractAddress = 'admin'.try_into().unwrap();
let mut calldata = array![admin_address.into()];
let (address0, _) = deploy_syscall(
ownable::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
)
.unwrap();
let mut contract0 = OwnableTraitDispatcher { contract_address: address0 };

assert(contract0.owner() == admin_address, 'Wrong owner');
}
}

87 changes: 0 additions & 87 deletions examples/Ownable-Starknet/tests/test_ownable.cairo

This file was deleted.

1 change: 0 additions & 1 deletion src/ch02-02-starkli-scarb-katana.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ mod hello {
}
#[external(v0)]
fn set_name(ref self: ContractState, name: felt252) {
let previous = self.name.read();
self.name.write(name);
}
}
Expand Down
25 changes: 11 additions & 14 deletions src/ch02-05-testnet-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ the Account Descriptor is a JSON file detailing the wallet’s address and
public key.

In order for an account to be used as a signer it must be deployed to the appropriate network,
Starknet Sepolia or mainnet, and funded. For this example we are going to use Sepolia Testnet. To deploy your wallet, visit [Smart Wallet Setup](https://book.starknet.io/ch01-00-getting-started.html#smart-wallet-setup).
Starknet Goerli, Sepolia or mainnet, and funded. For this example we are going to use Goerli Testnet. To deploy your wallet, visit [Smart Wallet Setup](https://book.starknet.io/ch01-00-getting-started.html#smart-wallet-setup).
Now you’re ready to interact with Starknet smart contracts.

### Creating a Signer
Expand Down Expand Up @@ -192,6 +192,9 @@ There are three main options for RPC providers, sorted by ease of use:
Starknet Book](https://book.starknet.io/chapter_4/node.html) or
[Kasar](https://www.kasar.io/) for setup guides.

3. **Free RPC vendor**: These 3 networks are eligible for free RPC vendors: mainet, goerli, sepolia.
You can choose [Blast](https://blastapi.io/public-api/starknet) or [Nethermind](https://data.voyager.online/)

### Creating an Account Descriptor

An Account Descriptor informs Starkli about your smart wallet’s unique
Expand All @@ -202,10 +205,10 @@ input and generates the account descriptor file. The account descriptor
file is a JSON file that contains the details of your smart wallet. We also have to pass the rpc provider here.

```bash
starkli account fetch <SMART_WALLET_ADDRESS> --output ~/.starkli-wallets/deployer/my_account_1.json --rpc https://starknet-sepolia.infura.io/v3/<API_KEY>
starkli account fetch <SMART_WALLET_ADDRESS> --output ~/.starkli-wallets/deployer/my_account_1.json --rpc https://starknet-testnet.public.blastapi.io/rpc/v0_6
```

Note: If you don't specify the rpc provider, Starkli will use Goerli, which will be deprecated soon.
Note: Here we used the Public RPC Endpoint v0.6 Starknet (Goerli) Testnet from **Blast**. If you don't specify the rpc provider, Starkli will use Goerli, which will be deprecated in the upcoming months. Thus you can check the rpc url for Sepolia network on [Blast](https://blastapi.io/public-api/starknet).

> ⚠️ **Contract not found?**
>
Expand All @@ -217,14 +220,14 @@ Note: If you don't specify the rpc provider, Starkli will use Goerli, which will
>
> #### 🟩 Solution:
>
> It means you probably just created a new wallet and it has **not been deployed yet**. To accomplish this you have to fund your wallet with tokens and **transfer tokens** to a **different** wallet address. Detailed intructons can be found in the [Get Seplia Tokens](./ch02-05-01-start-with-sepolia.md) section.
> It means you probably just created a new wallet and it has **not been deployed yet**. To accomplish this you have to fund your wallet with tokens and **transfer tokens** to a **different** wallet address. For goerli tokens you can check this [faucet](https://faucet.goerli.starknet.io/). For Sepolia tokens detailed intructons can be found in the [Get Sepolia Tokens](./ch02-05-01-start-with-sepolia.md) section.
>
> **Still doesn't work?**
>
> Check if your wallet's testnet network isn't yet set with Sepolia, that means you have to after deploying your wallet testnet, use instead the soon to be deprecated Goerli network:
> Check if your wallet's testnet network isn't yet set with Goerli or Sepolia, try again with your blast rpc url.
>
> ```bash
> starknet account fetch ... --rpc https://starknet-goerli.infura.io/v3/<API_KEY>
> starknet account fetch ... --rpc https://starknet-testnet.public.blastapi.io/rpc/
> ```
>
> ⚠️ And if you use Goerli, make sure you use it in subsequent commands as well.
Expand Down Expand Up @@ -285,6 +288,7 @@ another for the Account Descriptor file.
```bash
export STARKNET_ACCOUNT=~/.starkli-wallets/deployer/my_account_1.json
export STARKNET_KEYSTORE=~/.starkli-wallets/deployer/my_keystore_1.json
export STARKNET_RPC=https://starknet-testnet.public.blastapi.io/rpc/v0_6
```
Setting these variables makes running Starkli commands easier and more
Expand Down Expand Up @@ -313,13 +317,6 @@ This creates a compiled contract in `target/dev/` as
`ownable_starknet_ownable.compiled_contract_class.json` (in Chapter 2 of the book we will learn
more details about Scarb).
With the smart contract compiled, we’re ready to declare it using
Starkli. Then we can set the STARKNET_RPC environment variable to make command invocations easier:
```bash
export STARKNET_RPC="https://starknet-sepolia.infura.io/v3/<API_KEY>"
```
### Declaring Your Contract
Run this command to declare your contract using the default Starknet
Expand All @@ -330,7 +327,7 @@ Sequencer’s Gateway:
```
According to the `STARKNET_RPC` url, starkli can recognize the target
blockchain network, in this case "sepolia", so it is not necessary
blockchain network, in this case "goerli", so it is not necessary
explicitly specify it.
Unless you’re working with custom networks where it’s infeasible for
Expand Down
Loading

0 comments on commit 08cfe2d

Please sign in to comment.