forked from xJonathanLEI/starknet-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
declare_cairo0_contract.rs
43 lines (37 loc) · 1.36 KB
/
declare_cairo0_contract.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::sync::Arc;
use starknet::{
accounts::{Account, ExecutionEncoding, SingleOwnerAccount},
core::{
chain_id,
types::{contract::legacy::LegacyContractClass, BlockId, BlockTag, FieldElement},
},
providers::SequencerGatewayProvider,
signers::{LocalWallet, SigningKey},
};
#[tokio::main]
async fn main() {
let contract_artifact: LegacyContractClass =
serde_json::from_reader(std::fs::File::open("/path/to/contract/artifact.json").unwrap())
.unwrap();
let provider = SequencerGatewayProvider::starknet_alpha_goerli();
let signer = LocalWallet::from(SigningKey::from_secret_scalar(
FieldElement::from_hex_be("YOUR_PRIVATE_KEY_IN_HEX_HERE").unwrap(),
));
let address = FieldElement::from_hex_be("YOUR_ACCOUNT_CONTRACT_ADDRESS_IN_HEX_HERE").unwrap();
let mut account = SingleOwnerAccount::new(
provider,
signer,
address,
chain_id::TESTNET,
ExecutionEncoding::Legacy,
);
// `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest
// block. Optionally change the target block to pending with the following line:
account.set_block_id(BlockId::Tag(BlockTag::Pending));
let result = account
.declare_legacy(Arc::new(contract_artifact))
.send()
.await
.unwrap();
dbg!(result);
}