Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Use dotenv and add multi arch build
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementWalter committed Jul 28, 2023
1 parent 39a0b1c commit 9a71690
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 81 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "main"

jobs:
build_and_push:
backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -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
7 changes: 7 additions & 0 deletions backend/.env.example
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=
20 changes: 11 additions & 9 deletions backend/main.js
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}...`);
});
99 changes: 50 additions & 49 deletions backend/onchain.js
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();
}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"
services:
starkcet-front:
build:
Expand All @@ -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:
Expand Down
31 changes: 11 additions & 20 deletions frontend/src/components/Header.js
Original file line number Diff line number Diff line change
@@ -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 (
<Main>
<MainTitle>
<Image src={kakarotNameLogo} alt="Avatar" />
<MainTitle>
<Image src={kakarotNameLogo} alt="Avatar" />
</MainTitle>
<Navigation>
</Navigation>
<Navigation></Navigation>
</Main>
)
);
}

const Main = styled.div`
Expand All @@ -25,7 +21,7 @@ const Main = styled.div`
@media (max-width: 1000px) {
padding: 0px 10px;
}
`
`;

const MainTitle = styled.h1`
color: #2d2d71;
Expand All @@ -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;
Expand All @@ -47,8 +39,7 @@ const Navigation = styled.div`
@media (max-width: 1000px) {
gap: 10px;
}
`

`;

const Image = styled.img`
width: 50px;
Expand All @@ -57,4 +48,4 @@ const Image = styled.img`
width: 35px;
height: 35px;
}
`
`;

0 comments on commit 9a71690

Please sign in to comment.