Skip to main content

Accounts

Initialise the first account

info

When running madara in the development environment, follow these steps to initialise the first account

(0x3 is the first account that comes with the madara development environment by default)

sncast --url http://127.0.0.1:9944 \
account add \
--name 0x3 \
--address 0x3 \
--private-key 0x00c1cf1490de1352865301bb8705143f3ef938f97fdf892f1090dcb5ac7bcd1d

Ways to deploy accounts

  • Deploy directly via public key
  • Deploying via sncast account creation

By default, the class-hash of the deployment account is integrated in the madara node. The class hash is 0x6280083f8c2a2db9f737320d5e3029b380e0e820fe24b8d312a6a34fdba0cd.

What is Class Hash

info

Class Hash is an important concept in StarkNet. class hash is a hash value that uniquely identifies the code of a StarkNet contract. starkNet hashes the code of a contract into a fixed length value and uses this value to represent the contract. This helps ensure the uniqueness and security of the contract and allows for efficient state updates and validation on the chain.

A more detailed description of contract class_hash can be found in the starknet documentation

Deploying accounts with public keys

sncast \
--account 0x3 \
--url http://127.0.0.1:9944 \
deploy \
--class-hash "0x6280083f8c2a2db9f737320d5e3029b380e0e820fe24b8d312a6a34fdba0cd" \
--constructor-calldata "<PublicKey>"

Example

PublicKey 0x254020ae8af1612e53737a32275ad03b91e55467924a9c7de7915cba856d61

You can replace this public key with your own public key

DeployAccount

The contract address contract_address returned by the command line is your account address.

Create account deployment with sncast

Steps in the process

  • Create an account with sncast
  • Use the first initial account to charge the newly created account.
  • Deploying the newly created account

Creating an account

sncast \
--url http://127.0.0.1:9944 \
account create \
--name <account_name> \
--class-hash 0x6280083f8c2a2db9f737320d5e3029b380e0e820fe24b8d312a6a34fdba0cd

AccountCreate

Recharge

sncast -u http://127.0.0.1:9944 \
--account 0x3 \
invoke --contract-address 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 \
--function "transfer" \
--calldata "<YourAccountAddress> 10000 10000"

UpdateCreateAccountBalance

Deployment

sncast --url http://127.0.0.1:9944 \
account deploy \
--name <account_name> --max-fee 86460

DeployCreateAccount

Check Balance

Token contract default madara has been integrated. Contract address contract-address is 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7.

info

The address of this Token contract --contract-address is 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7. Default integration into Madara

sncast -u http://127.0.0.1:9944 \
call --contract-address 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 \
--function "balanceOf" --calldata <YourAddress>

As you can see, the account balance for this new deployment is 0

GetAccountBalance

Account recharge

Transferring money

Now we use the first initial account 0x3 to transfer some balance to this newly deployed account

sncast -u http://127.0.0.1:9944 --account 0x3 \
invoke --contract-address 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 \
--function "transfer" \
--calldata "<YourAddress> 1 100000"

AccountTransfer

Checking the balance again, you can see that the account now has a balance

AccountTransfer