-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path3.deployTokenSepolia.ts
79 lines (63 loc) · 3.21 KB
/
3.deployTokenSepolia.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Declare/Deploy in Sepolia an ERC20 token
// Coded with Starknet.js v6.9.0
// launch with npx ts-node src/scripts/merkleTree/airdropSJS6Sepolia/3.deployTokenSepolia.ts
import { Account, Call, Calldata, CallData, Contract, json, RPC, RpcProvider, shortString } from 'starknet';
import { infuraKey, account1MainnetAddress, account1MainnetPrivateKey, blastKey } from "../../../A-MainPriv/mainPriv";
import { account0OZSepoliaAddress, account0OZSepoliaPrivateKey } from "../../../A1priv/A1priv";
import fs from "fs";
import * as dotenv from "dotenv";
dotenv.config();
async function main() {
// initialize Provider. Adapt to your needs
// **** Starknet-devnet-rs
// const provider = new RpcProvider({ nodeUrl: "http://127.0.0.1:5050/rpc" });
// **** Sepolia Testnet :
const provider = new RpcProvider({ nodeUrl: "https://free-rpc.nethermind.io/sepolia-juno/v0_7" });
// Check that communication with provider is OK
const ch = await provider.getChainId();
console.log("chain Id =", shortString.decodeShortString(ch), ", rpc", await provider.getSpecVersion());
// initialize account. Adapt to your case
// *** Devnet-rs
// const privateKey0 = "0x71d7bb07b9a64f6f78ac4c816aff4da9";
// const accountAddress0: string = "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691";
// *** initialize existing Sepolia Testnet account
const privateKey0 = account0OZSepoliaPrivateKey;
const accountAddress0 = account0OZSepoliaAddress;
// *** initialize existing Argent X mainnet account
// const privateKey0 = account1MainnetPrivateKey;
// const accountAddress0 = account1MainnetAddress
// *** initialize existing Sepolia Integration account
// const privateKey0 = account1IntegrationOZprivateKey;
// const accountAddress0 = account1IntegrationOZaddress;
const account0 = new Account(provider, accountAddress0, privateKey0);
console.log('existing_ACCOUNT_ADDRESS=', accountAddress0);
console.log('existing account connected.\n');
// deploy ERC20
const compiledSierraERC20 = json.parse(fs.readFileSync("./compiledContracts/cairo210/erc20OZ070decimals.sierra.json").toString("ascii"));
const compiledCasmERC20 = json.parse(fs.readFileSync("./compiledContracts/cairo210/erc20OZ070decimals.casm.json").toString("ascii"));
const myCallERC20 = new CallData(compiledSierraERC20.abi);
const myConstructorERC20: Calldata = myCallERC20.compile("constructor", {
name: "Starknet.js-v6-celebration",
symbol: "SJS6",
decimals: 0,
initial_supply: 40_000,
recipient: account0.address,
});
const deployResponseERC20 = await account0.declareAndDeploy({
contract: compiledSierraERC20,
casm: compiledCasmERC20,
constructorCalldata: myConstructorERC20
});
const erc20Address = deployResponseERC20.deploy.contract_address;
const erc20ClassHash = deployResponseERC20.declare.class_hash;
console.log("ERC20 contract :");
console.log("class_hash =", erc20ClassHash);
console.log("address =", erc20Address);
console.log("✅ test completed.");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});