This is a social platform system based on blockchain technology, supporting functions such as posting, commenting, and liking.
twichain/
├── cmd/
│ └── main.go
├── configs/
│ └── config.yaml
├── internal/
│ ├── blockchain/
│ ├── config/
│ ├── crypto/
│ ├── network/
│ └── storage/
└── test/
- Go 1.23.3+
- Go 1.23.3+
- Python 3.9+ (for test)
- SQLite3
go mod tidy
// go build -o twichain cmd/main.gogo run cmd/main.go
// ./twichain -config configs/config.yamlThe default server will start at http://localhost:8080
POST /transactions/new
Content-Type: application/json
{
"sender": "Sender's Public Key (256-bit hexadecimal)",
"receiver": "Recipient's Public Key (256-bit hexadecimal)",
"message": "Message content",
"signature": "EdDSA Signature",
"is_like": false,
"target_post_id": "Target post transaction ID when liking or commenting"
}Return complete blockchain data
GET /chainregister a node on an exsit network
POST /nodes/register
Content-Type: application/json
{
"node": "localhost:8080"
}For broadcasting a node
POST /nodes/new
Content-Type: application/json
{
"node": "localhost:8080"
}For broadcasting a block
POST /block/receive
Content-Type: application/json
{
"node": "localhost:8080"
}The system uses Ed25519 for signature verification:
- Generate a key pair:
# python example
private_key_bytes = os.urandom(32)
private_key = ed25519.SigningKey(private_key_bytes)
public_key = private_key.get_verifying_key()- Sign message:
- Normal posting/commenting: Use message content signature
- Like: Use target post ID signature
config.yaml:
server:
port: 8080
database:
path: "data/blockchain.db"
blockchain:
difficulty: 2
node_address: ""go build -o test/twichain cmd/main.go
cd test
uv init .
uv add requests ed25519 tqdm
uv run consensus_test.py- Post in the main_space:
receiver for main_space is a fixed value
tx_data = {
"sender": "User Public Key",
"receiver": "69c5f684026e6bd3e2a8f175a892ca6858cb9936b3c525ce11b981f848a69fc2",
"message": "This is a test post",
"is_like": false
"target_post_id": ""
}- Like post:
tx_data = {
"sender": "User Public Key",
"receiver": "Post Author's Public Key",
"message": "",
"is_like": true,
"target_post_id": "Transaction ID of Target Post"
}- Comment post:
tx_data = {
"sender": "User Public Key",
"receiver": "Post Author's Public Key",
"message": "This is a comment",
"is_like": false,
"target_post_id": "Transaction ID of Target Post"
}Welcome to submit a Pull Request or raise an Issue!
This project is open-sourced under the MIT License, see the LICENSE file for details.
