Example of simple Ethereum API server with endpoints, and a client NFC app.
/createWallet
create an ethereum wallet/getBalance
checking wallet balance/transaction
making a transaction# Go to https://infura.io/ and get your ETH API key.
# It looks like this:
# https://rinkeby.infura.io/v3/3fe7c90a4ec34aae900a7900d3fb48dc
# You can use mine for test, but it's free so please create your own at https://infura.io/
# Put your key in 'src/config.json' under 'ethereumNetwork'
# Install dependencies
npm install
# Start developing
npm run dev
# Start production server
npm start
{
"port": 8080, // port to launch app to
"bodyLimit": "1kb", // max size of request json object
"ethereumNetwork": "" // Infura API key
}
/createWallet
GET localhost:8080/createWallet
# response
{
"address": CREATED_WALLET,
"privateKey": PRIVATE_KEY
}
/getBalance/SOME_ETH_ADDRESS
GET localhost:8080/getBalance/SOME_ETH_ADDRESS
# response
{
"ethAddress": SOME_ETH_ADDRESS,
"balance": BALANCE
}
/transaction
POST to localhost:8080/transaction
BODY
{
"privateKey": YOUR_PRIVATE_KEY,
"amount": AMOUNT,
"destination": DESTINATION_WALLET
}
# response
{
"txHash": TRANSACTION_HASH
}
As a client we are using NFC Tools Pro to program and write the wallet "app" on the NFC chip.
The "app" has 25 tasks and total 828 bytes.
# Download 'xETH_profile.json' and save it on your phone somewhere.
# This file is the main app file needed.
# Open NFC Tasks app and go to Settings/User variables and create next important five variables and fill in with your details:
- ADDRESS # put your public address on ETH here
- PRIVATEKEY # put private key here (soon support encrypted with password)
- BALANCEURL # put balance endpoint here, eg.: https://<your-host>/getBalance/<your-eth-public-address>
- TRANSACTURL # put transaction endpoint here, eg.: https://<your-host>/transaction
- CREATEURL # put your create endpoin here, eg.: https://<your-host>/createWallet
# Now create next empty variables:
- AMOUNT # temp store for sending amount
- BALANCE # temp store for showing balance
- CHOICE # temp store for menu choice acions
- DESTINATION # temp store address that we want to send ETH
- TXHASH # temp store for showing
- WALLET # temp store created address info
We configured app to work on Rinkeby test net, so it’s safe to play with.
If you want to use it on Mainnet, just get that Infura API mainet end-point, and copy it to your 'src/config.json' file.
MIT
Thanks to @wingleung for simple api code https://github.com/wingleung/ethereum-wallet-api-example