sw4-account-creator
is a streamlined, single-page web server designed specifically for the StatelessNET chain. This project is part of the event Stake Wars IV: Attack of the Transactions. Built on the robust actix-web
framework, it offers a user-friendly interface for creating new accounts on the StatelessNET chain, which is a feature-preview network operational during the event.
- Account Creation: Users can easily create a new account by providing their desired account ID and public Ed25519 key.
- Transaction Handling: The server automates the process of sending transactions on behalf of a top-level account (configured in the settings) to establish the new account.
- Funding Accounts: Newly created accounts are automatically funded with a predefined amount of NEAR tokens, ensuring immediate usability.
- Single-page template with a form for account creation
- Connect HTMX(https://htmx.org/) to the page
- Set up a form submission and replace the form with the result (partial template)
- Parse
account_id
andpublic_key
from the form - Response with a meaningul error message if the form is not valid
- Validate account is not taken (as simple as possible)
- Public key is a valid Ed25519 key
- Retry in case of nonce conflict
- (Optional) Protect from spamming
- Craft a transaction to create the account
- Sign the transaction with the key of the top-level account
- Top-level account and its key are configured in the settings
- Feature
contract-helper
that provides essential API for the Wallets (similar to thecontract-helper
)-
GET account/keys/{public_key}
Finds all the accounts with the given public key -
GET account/{account_id}/txns
Finds all the transactions for the given account -
GET account/{account_id}/likelyTokensFromBlock
Finds all the assets most likely to be [fungible] tokens for the given account from the given block -
GET account/{account_id}/likeleNFTsFromBlock
Finds all the assets most likely to be NFTs for the given account from the given block -
POST account/create
Creates a new account with the givenaccount_id
andpublic_key
-
The server is configured using environment variables. The following variables are required:
NEAR_RPC_URL
- URL of the NEAR RPC endpointBASE_SIGNER_ACCOUNT_ID
- Account ID of the top-level account that will sign transactionsBASE_SIGNER_SECRET_KEY
- Private key of the top-level accountFUNDING_AMOUNT
- Amount of NEAR tokens to fund new accounts with (default 100NEAR)SERVER_PORT
- Port to listen on (default 10000)- [
contract-helper
feature]DATABASE_URL
- PostgreSQL connection string to the ExplorerDB
It is expected the server will be running in Docker container. The following commands will build and run the server in a container:
docker build -t sw4-account-creator .
Put the configuration in a file called .env
in the root of the project. The file should look like this:
NEAR_RPC_URL=http://localhost:3030
BASE_SIGNER_ACCOUNT_ID=near
BASE_SIGNER_SECRET_KEY=ed25519:...
FUNDING_AMOUNT=100000000000000000000000000
SERVER_PORT=10000
RUST_LOG=info
Then run the server with:
docker run --env-file .env -p 10000:10000 sw4-account-creator
./targer/release run --server-port 8080 --near-rpc-url http://localhost:3030 --base-signer-account-id near --base-signer-secret-key "ed25519:..." --funding-amount 100000000000000000000000000