Doc : https://www.starknetjs.com/docs/API/
npm install -g yarn
mkdir starknet-project
cd starknet-project
python3 -m venv cairo-env
source cairo-env/bin/activate
pip install cairo-lang
pip install cairo-nile
nile install
nile init
pip install openzeppelin-cairo-contracts
yarn init
yarn add starknet@next
touch index.js
And update your package.json
file adding the line : "type": "module",
To test our installation we are going to compile a Starknet Account Smart Contract and deploying it using StarknetJS
Create a file under the contracts
folder name ArgentAccount.cairo
with this content
# contracts/MyToken.cairo
%lang starknet
from openzeppelin.account.Account import constructor
And an ERC20 token at contracts/ERC20.cairo
:
# contracts/MyToken.cairo
%lang starknet
from openzeppelin.token.erc20.ERC20 import constructor
And then Compile it using nile compile contracts/ArgentAccount.cairo --account_contract
and nile compile contracts/ERC20.cairo
command.
Then in your index.js
file :
import fs from "fs";
import {
Contract,
defaultProvider,
ec,
json,
stark,
} from "starknet";
console.log("Reading Argent Account Contract...");
const compiledArgentAccount = json.parse(
fs.readFileSync("./artifacts/OZAccount.json").toString("ascii")
);
// Generate public and private key pair.
const privateKey = stark.randomAddress();
const starkKeyPair = ec.genKeyPair(privateKey);
const starkKeyPub = ec.getStarkKey(starkKeyPair);
// Deploy the Account contract and wait for it to be verified on StarkNet.
console.log("Deployment Tx - Account Contract to StarkNet...");
const accountResponse = await defaultProvider.deployContract({
contract: compiledArgentAccount,
constructorCalldata: [starkKeyPub],
addressSalt: starkKeyPub,
});
// Wait for the deployment transaction to be accepted on StarkNet
console.log("Waiting for Tx "+ accountResponse.transaction_hash +" to be Accepted on Starknet - Argent Account Deployment...");
await defaultProvider.waitForTransaction(accountResponse.transaction_hash);
console.log("✨ Account Deployed at "+ starkKeyPub +" !!")
console.log(accountResponse.address)
//Ready to be used !!!
const accountContract = new Contract(
compiledArgentAccount.abi,
accountResponse.address
);
You now can deploy your contract using node index.js
!