NEWTON
Asked
6 months ago
5
views
0
How can I connect a predeployed StarkNet account in Starknet-devnet using starknetjs. Is there any difference with connect an existing account (in any network)?
Newton
asked
6 months ago
0
Accepted answer
Once your provider is initialized, you can connect an existing account. You need 2 data :
import { Account, ec, Provider } from "starknet";
When you launch starknet-devnet, 10 accounts are predeployed with 100 dummy ETH in each. Addresses and private keys are displayed on the console at initialization. These data will change at each launch ; to freeze them, launch with : starknet-devnet --seed 0
. The result for account #0 :
Address: 0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a Public key: 0x7e52885445756b313ea16849145363ccb73fb4ab0440dbac333cf9d13de82b9 Private key: 0xe3e70682c2094cac629f6fbed82c07cd
Then you can use this code :
// initialize provider const provider = new Provider({ sequencer: { baseUrl:"<http://127.0.0.1:5050>" } }); // initialize existing predeployed account 0 of Devnet const privateKey = "0xe3e70682c2094cac629f6fbed82c07cd"; const starkKeyPair = ec.getKeyPair(privateKey); const accountAddress = "0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a"; const account = new Account(provider, accountAddress, starkKeyPair);
Your account is now connected, and you can use it.
The code is exactly the same, you have just :
import * as dotenv from "dotenv"; dotenv.config(); // intialize provider const provider = new Provider({ sequencer: { baseUrl:"goerli-alpha" } }); // initialize existing account const privateKey = process.env.OZ_NEW_ACCOUNT_PRIVKEY; const starkKeyPair = ec.getKeyPair(privateKey); const accountAddress = "0x051158d244c7636dde39ec822873b29e6c9a758c6a9812d005b6287564908667"; const account = new Account(provider, accountAddress, starkKeyPair);
Newton
answered
6 months ago
How can I connect to deployed StarkNet contract using starknetjs?
How do I connect my DAPP to Starknet-devnet using starknetjs?
How do I connect my DAPP to a private Starknet network using starknetjs?
How do I connect my DAPP to a Starknet node using starknetjs?
How do I connect my DAPP to Starknet mainnet using starknetjs?
How do I connect my DAPP to Starknet testnet using starknetjs?
How do I create account using starknetjs?
ApeWorX: Using ape starknet accounts list
How to use Kakarot for my Solidity Contracts?
Cairo Array Item Removal
What is the most valuable project on starknet?
How do I interact with my Pathfinder node?
How to send tokens through StarkNet.py?
Why abi of warp compiled contract does not match original solidity abi?