diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf4cc92..0a2b473 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: - "main" jobs: - build_and_push: + backend: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -26,9 +26,26 @@ jobs: push: true tags: ghcr.io/kkrt-labs/kakacet/backend:latest context: ./backend + platforms: linux/amd64,linux/arm64 + + frontend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push uses: docker/build-push-action@v4 with: push: true tags: ghcr.io/kkrt-labs/kakacet/frontend:latest context: ./frontend + platforms: linux/amd64,linux/arm64 diff --git a/backend/.env.example b/backend/.env.example new file mode 100644 index 0000000..b3a067e --- /dev/null +++ b/backend/.env.example @@ -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= diff --git a/backend/main.js b/backend/main.js index 1b603fc..1cdd51f 100644 --- a/backend/main.js +++ b/backend/main.js @@ -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}...`); }); diff --git a/backend/onchain.js b/backend/onchain.js index f1c58b7..dc5fa93 100644 --- a/backend/onchain.js +++ b/backend/onchain.js @@ -1,25 +1,25 @@ -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); @@ -27,45 +27,46 @@ 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(); } diff --git a/docker-compose.yml b/docker-compose.yml index 1ac5adf..13c03f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3' +version: "3" services: starkcet-front: build: @@ -18,7 +18,7 @@ services: - PRIVATE_KEY=0x0300001800000000300000180000000000030000000000003006001800006600 - STARKNET_ACCOUNT_ADDRESS=0x03ee9e18edc71a6df30ac3aca2e0b02a198fbce19b7480a63a0d71cbd76652e0 - TOKEN_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 - - KAKAROT_ADDRESS=0x66a5454898f533792a1b3563d808c680a1cf6dd485797fc7044d71d88c49205 + - KAKAROT_ADDRESS=0x66a5454898f533792a1b3563d808c680a1cf6dd485797fc7044d71d88c49205 - RPC_URL=http://host.docker.internal:5050 - AMOUNT_TRANSFERED=1000000000000000 networks: diff --git a/frontend/src/components/Header.js b/frontend/src/components/Header.js index 99534fe..b26dada 100644 --- a/frontend/src/components/Header.js +++ b/frontend/src/components/Header.js @@ -1,20 +1,16 @@ -import './style/index.css' -import kakarotLogo from '../assets/kakarot_logo.svg' -import kakarotNameLogo from '../assets/kakarot_name_logo.svg' -import styled from "styled-components" - +import styled from "styled-components"; +import kakarotNameLogo from "../assets/kakarot_name_logo.svg"; +import "./style/index.css"; export default function Header() { - return (
- - Avatar + + Avatar - - +
- ) + ); } const Main = styled.div` @@ -25,7 +21,7 @@ const Main = styled.div` @media (max-width: 1000px) { padding: 0px 10px; } -` +`; const MainTitle = styled.h1` color: #2d2d71; @@ -34,11 +30,7 @@ const MainTitle = styled.h1` @media (max-width: 1000px) { font-size: 30px; } -` - -const EndTitle = styled.span` - font-weight: 500; -` +`; const Navigation = styled.div` display: flex; @@ -47,8 +39,7 @@ const Navigation = styled.div` @media (max-width: 1000px) { gap: 10px; } -` - +`; const Image = styled.img` width: 50px; @@ -57,4 +48,4 @@ const Image = styled.img` width: 35px; height: 35px; } -` +`;