-
Notifications
You must be signed in to change notification settings - Fork 33
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
Showing
14 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,18 @@ | ||
{ | ||
"name": "linera-fun-frontend", | ||
"version": "1.0.0", | ||
"description": "Frontend for Linera.fun - A token creation dApp on Linera blockchain", | ||
"main": "index.js", | ||
"dependencies": { | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"axios": "^0.21.1" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
} | ||
} | ||
|
Empty file.
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,13 @@ | ||
import React from "react"; | ||
import CreateToken from "./components/CreateToken"; | ||
|
||
function App() { | ||
return ( | ||
<div className="App"> | ||
<h1>Linera.fun - Token Creation dApp</h1> | ||
<CreateToken /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
42 changes: 42 additions & 0 deletions
42
winrhcp/linera-token-frontend/src/components/CreateToken.js
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,42 @@ | ||
import React, { useState } from "react"; | ||
import { createToken } from "../services/lineraService"; | ||
|
||
function CreateToken() { | ||
const [name, setName] = useState(""); | ||
const [symbol, setSymbol] = useState(""); | ||
const [totalSupply, setTotalSupply] = useState(""); | ||
const [message, setMessage] = useState(""); | ||
|
||
const handleCreateToken = async () => { | ||
const result = await createToken(name, symbol, parseInt(totalSupply)); | ||
setMessage(result ? "Token created successfully!" : "Error creating token."); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h2>Create Token</h2> | ||
<input | ||
type="text" | ||
placeholder="Token Name" | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
/> | ||
<input | ||
type="text" | ||
placeholder="Symbol" | ||
value={symbol} | ||
onChange={(e) => setSymbol(e.target.value)} | ||
/> | ||
<input | ||
type="number" | ||
placeholder="Total Supply" | ||
value={totalSupply} | ||
onChange={(e) => setTotalSupply(e.target.value)} | ||
/> | ||
<button onClick={handleCreateToken}>Create Token</button> | ||
<p>{message}</p> | ||
</div> | ||
); | ||
} | ||
|
||
export default CreateToken; |
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,5 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import App from "./App"; | ||
|
||
ReactDOM.render(<App />, document.getElementById("root")); |
17 changes: 17 additions & 0 deletions
17
winrhcp/linera-token-frontend/src/services/lineraService.js
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,17 @@ | ||
import axios from "axios"; | ||
|
||
const BASE_URL = "http://127.0.0.1:8080"; // Update to your backend URL | ||
|
||
export const createToken = async (name, symbol, totalSupply) => { | ||
try { | ||
const response = await axios.post(`${BASE_URL}/create_token`, { | ||
name, | ||
symbol, | ||
total_supply: totalSupply, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
console.error("Token creation error:", error); | ||
return { success: false, message: error.message }; | ||
} | ||
}; |
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,11 @@ | ||
[package] | ||
name = "linera_token_creation" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
linera-sdk = "0.12.1" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
actix-web = "4.0" | ||
tokio = { version = "1", features = ["full"] } |
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,9 @@ | ||
### Linera.fun | ||
|
||
Linera.fun is a decentralized application built on the Linera blockchain, designed to make token creation fun, accessible, and community-driven. Inspired by platforms like Pump.fun, Linera.fun enables anyone to create tokens easily, leveraging the unique scalability and speed of the Linera network. Whether you're creating tokens for community engagement, social events, or personal projects, Linera.fun makes it possible in just a few steps. | ||
|
||
### Key Features | ||
- Effortless Token Creation: Create tokens by entering basic information (token name, symbol, and supply) in a quick, user-friendly interface. | ||
- Powered by Linera: Built on Linera’s innovative blockchain, ensuring low fees, high throughput, and seamless transaction experiences. | ||
- Instant Liquidity: Tokens are immediately tradable within the Linera ecosystem, allowing rapid community interaction and engagement. | ||
- Designed for Community and Virality: Like memecoins on other platforms, tokens created on Linera.fun can gain popularity through community-driven, social dynamics. |
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,10 @@ | ||
use linera_sdk::Contract; | ||
use crate::views::TokenView; | ||
use crate::types::Token; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub async fn create_token(name: &str, symbol: &str, total_supply: u32) -> Result<(), String> { | ||
let mut view = TokenView::load().await; | ||
view.create_token(name, symbol, total_supply); | ||
view.save().await.map_err(|_| "Error saving token".to_string()) | ||
} |
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,4 @@ | ||
#[derive(Debug)] | ||
pub enum TokenError { | ||
BlockchainError, | ||
} |
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,32 @@ | ||
mod contract; | ||
mod views; | ||
mod types; | ||
mod errors; | ||
|
||
use actix_web::{post, web, App, HttpServer, Responder, HttpResponse}; | ||
use serde::Deserialize; | ||
use crate::contract::create_token; | ||
use crate::types::TokenRequest; | ||
|
||
#[post("/create_token")] | ||
async fn create_token_endpoint(req: web::Json<TokenRequest>) -> impl Responder { | ||
let token_name = &req.name; | ||
let token_symbol = &req.symbol; | ||
let total_supply = req.total_supply; | ||
|
||
match create_token(token_name, token_symbol, total_supply).await { | ||
Ok(_) => HttpResponse::Ok().json("Token created successfully"), | ||
Err(err) => HttpResponse::BadRequest().json(format!("Error: {:?}", err)), | ||
} | ||
} | ||
|
||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
HttpServer::new(|| { | ||
App::new() | ||
.service(create_token_endpoint) | ||
}) | ||
.bind("127.0.0.1:8080")? | ||
.run() | ||
.await | ||
} |
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,17 @@ | ||
use serde::{Serialize, Deserialize}; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct Token { | ||
pub name: String, | ||
pub symbol: String, | ||
pub total_supply: u32, | ||
pub balances: HashMap<String, u32>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct TokenRequest { | ||
pub name: String, | ||
pub symbol: String, | ||
pub total_supply: u32, | ||
} |
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,20 @@ | ||
use linera_sdk::View; | ||
use crate::types::Token; | ||
use std::collections::HashMap; | ||
|
||
#[derive(View)] | ||
pub struct TokenView { | ||
pub tokens: HashMap<String, Token>, | ||
} | ||
|
||
impl TokenView { | ||
pub fn create_token(&mut self, name: &str, symbol: &str, total_supply: u32) { | ||
let token = Token { | ||
name: name.to_string(), | ||
symbol: symbol.to_string(), | ||
total_supply, | ||
balances: HashMap::new(), | ||
}; | ||
self.tokens.insert(name.to_string(), token); | ||
} | ||
} |