This repository demonstrates basic usage of Wallet API using Docker.
Note: The .env.testnet file in this repository is already configured with an admin account on testnet. You can skip to the next session to get started.
Wallet API needs an admin account to create more accounts. We'll use the testnet faucet to create an account and update .env.testnet.
flow keys generate
Go to https://faucet.flow.com/ to create and fund an account using the generated public key.
Configure .env.testnet:
FLOW_WALLET_ADMIN_ADDRESS=<put address here>
FLOW_WALLET_ADMIN_PRIVATE_KEY=<put private key here>
Wallet API is available as a Docker image. The docker-compose.yml file bundles it with a database. It also references an environment file (.env.testnet) as configuration.
To run:
docker-compose up -d
Verify:
docker ps
Check out here for list of config options.
Check out API Documentation for list of endpoints.
curl http://localhost:3000/v1/debug
curl -X POST "http://localhost:3000/v1/accounts" -H "Idempotency-Key: 1"
Idempotency-Key
should be unique for each new API call. Since Wallet API is non-blocking by default, the above call will return a jobId
that can be used to fetch the request's status:
curl http://localhost:3000/v1/jobs/160a2510-c0ef-467d-ae01-ad5a3b1ba616
When the job is COMPLETE
the new account's address will be available in the result
field.
You can also list all accounts:
curl http://localhost:3000/v1/accounts
Note: You can add ?sync=1
to the end of the URL to make a blocking transaction request. This will skip the job system to return a result.
You can send transactions from custodied accounts:
curl -X POST "http://localhost:3000/v1/accounts/0x33b6a9a32ae5cded/transactions" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 2" \
-d '{"code":"transaction{prepare(a: AuthAccount){}}"}'
Remember to replace the account address with a valid custodial account. In response, a job will be created so you can check the result asynchronously. Transaction hash is also returned in transactionId
.
curl http://localhost:3000/v1/jobs/278de8cb-14b2-413e-bf04-8a83b99c0338
List an accounts transactions:
curl http://localhost:3000/v1/accounts/0x33b6a9a32ae5cded/transactions
Note: You can add ?sync=1
to the end of the URL to make a blocking transaction request. This will skip the job system to return a result:
curl -X POST "http://localhost:3000/v1/accounts/0x33b6a9a32ae5cded/transactions?sync=1" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 3" \
-d '{"code":"transaction{prepare(a: AuthAccount){}}"}'