This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
forked from zizou0x/starkcet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39a0b1c
commit 9a71690
Showing
6 changed files
with
99 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Env variables can be given in the compose file directly, but will also read from the .env | ||
PRIVATE_KEY= | ||
STARKNET_ACCOUNT_ADDRESS= | ||
TOKEN_ADDRESS= | ||
KAKAROT_ADDRESS= | ||
RPC_URL= | ||
AMOUNT_TRANSFERED= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import express from 'express'; | ||
import bodyParser from 'body-parser'; | ||
import cors from 'cors'; | ||
import { initRoutes } from './api.js'; | ||
import bodyParser from "body-parser"; | ||
import cors from "cors"; | ||
import express from "express"; | ||
import { initRoutes } from "./api.js"; | ||
|
||
const app = express(); | ||
app.use(bodyParser.json()); | ||
app.use(cors({ | ||
origin: 'http://localhost:3000' // React app is served from this origin | ||
})); | ||
const port = 4000 | ||
app.use( | ||
cors({ | ||
origin: "http://localhost:3000", // React app is served from this origin | ||
}) | ||
); | ||
const port = 4000; | ||
|
||
// Initialize routes | ||
initRoutes(app); | ||
|
||
app.listen(port, () => { | ||
console.log(`Server started, listening on port ${port}...`); | ||
console.log(`Server started, listening on port ${port}...`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,72 @@ | ||
import * as starknet from 'starknet'; | ||
import erc20Json from './erc20_abi.json' assert { type: 'json' }; | ||
import "dotenv/config"; | ||
import * as starknet from "starknet"; | ||
import erc20Json from "./erc20_abi.json" assert { type: "json" }; | ||
|
||
function getEnvVariable(name, defaultValue) { | ||
const value = process.env[name]; | ||
if (value !== undefined) { | ||
return value; | ||
} else if (defaultValue !== undefined) { | ||
return defaultValue; | ||
} else { | ||
throw new Error(`${name} environment variable is not defined`); | ||
} | ||
const value = process.env[name] || defaultValue; | ||
if (value === undefined) { | ||
throw new Error(`${name} environment variable is not defined`); | ||
} | ||
return value; | ||
} | ||
|
||
const ethTokenAddress = getEnvVariable('TOKEN_ADDRESS'); | ||
const address = getEnvVariable('STARKNET_ACCOUNT_ADDRESS'); | ||
const kakarotAddress = getEnvVariable('KAKAROT_ADDRESS'); | ||
const rpcUrl = getEnvVariable('RPC_URL'); | ||
const privateKey = getEnvVariable('PRIVATE_KEY'); | ||
const ethTokenAddress = getEnvVariable("TOKEN_ADDRESS"); | ||
const address = getEnvVariable("STARKNET_ACCOUNT_ADDRESS"); | ||
const kakarotAddress = getEnvVariable("KAKAROT_ADDRESS"); | ||
const rpcUrl = getEnvVariable("RPC_URL"); | ||
const privateKey = getEnvVariable("PRIVATE_KEY"); | ||
console.log("Faucet token address:", ethTokenAddress); | ||
console.log("Kakarot address:", kakarotAddress); | ||
|
||
const provider = new starknet.RpcProvider({ | ||
nodeUrl: rpcUrl, | ||
nodeUrl: rpcUrl, | ||
}); | ||
|
||
const account = new starknet.Account(provider, address, privateKey); | ||
|
||
const contract = new starknet.Contract(erc20Json, ethTokenAddress, provider); | ||
|
||
export async function getStarknetEoaAddress(ethAddress) { | ||
console.log('call kakarot.compute_starknet_address - ', ethAddress); | ||
const callResponse = await provider.callContract({ | ||
contractAddress: kakarotAddress, | ||
entrypoint: 'compute_starknet_address', | ||
calldata: [ethAddress], | ||
}); | ||
console.log("call kakarot.compute_starknet_address - ", ethAddress); | ||
const callResponse = await provider.callContract({ | ||
contractAddress: kakarotAddress, | ||
entrypoint: "compute_starknet_address", | ||
calldata: [ethAddress], | ||
}); | ||
|
||
return callResponse.result[0]; | ||
} | ||
return callResponse.result[0]; | ||
} | ||
|
||
export async function transfer(to) { | ||
console.log('Transfer to - ', to); | ||
let result = contract.populate('transfer', { | ||
recipient: to, | ||
amount: { | ||
low: process.env.AMOUNT_TRANSFERED, | ||
high: '0', | ||
}, | ||
}); | ||
console.log("Transfer to - ", to); | ||
let result = contract.populate("transfer", { | ||
recipient: to, | ||
amount: { | ||
low: process.env.AMOUNT_TRANSFERED, | ||
high: "0", | ||
}, | ||
}); | ||
|
||
console.log('Call detail - ', result); | ||
const nonce = await provider.getNonceForAddress(address); | ||
console.log('Nonce - ', nonce); | ||
const version = '0x1'; | ||
const maxFee = '0x11111111111'; | ||
let hash = await account.execute(result, undefined, { | ||
nonce, | ||
maxFee, | ||
version, | ||
}); | ||
console.log("Call detail - ", result); | ||
const nonce = await provider.getNonceForAddress(address); | ||
console.log("Nonce - ", nonce); | ||
const version = "0x1"; | ||
const maxFee = "0x11111111111"; | ||
let hash = await account.execute(result, undefined, { | ||
nonce, | ||
maxFee, | ||
version, | ||
}); | ||
|
||
console.log(hash); | ||
return hash | ||
console.log(hash); | ||
return hash; | ||
} | ||
|
||
|
||
export async function balanceOf(of) { | ||
console.log("Getting balance of: " + of) | ||
const balance = await contract.balanceOf(of); | ||
console.log("Balance -" + starknet.uint256.uint256ToBN(balance.balance).toString()) | ||
return starknet.uint256.uint256ToBN(balance.balance).toString() | ||
console.log("Getting balance of: " + of); | ||
const balance = await contract.balanceOf(of); | ||
console.log( | ||
"Balance -" + starknet.uint256.uint256ToBN(balance.balance).toString() | ||
); | ||
return starknet.uint256.uint256ToBN(balance.balance).toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters