Skip to content

Commit

Permalink
initial linera.fun (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
winrhcp authored Oct 29, 2024
1 parent 0fbda87 commit 761ee1f
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 0 deletions.
Empty file.
18 changes: 18 additions & 0 deletions winrhcp/linera-token-frontend/package.json
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.
13 changes: 13 additions & 0 deletions winrhcp/linera-token-frontend/src/App.js
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 winrhcp/linera-token-frontend/src/components/CreateToken.js
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;
5 changes: 5 additions & 0 deletions winrhcp/linera-token-frontend/src/index.js
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 winrhcp/linera-token-frontend/src/services/lineraService.js
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 };
}
};
11 changes: 11 additions & 0 deletions winrhcp/linera_token_creation/Cargo.toml
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"] }
9 changes: 9 additions & 0 deletions winrhcp/linera_token_creation/README.md
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.
10 changes: 10 additions & 0 deletions winrhcp/linera_token_creation/src/contract.rs
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())
}
4 changes: 4 additions & 0 deletions winrhcp/linera_token_creation/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[derive(Debug)]
pub enum TokenError {
BlockchainError,
}
32 changes: 32 additions & 0 deletions winrhcp/linera_token_creation/src/main.rs
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
}
17 changes: 17 additions & 0 deletions winrhcp/linera_token_creation/src/types.rs
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,
}
20 changes: 20 additions & 0 deletions winrhcp/linera_token_creation/src/views.rs
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);
}
}

0 comments on commit 761ee1f

Please sign in to comment.