GithubHelp home page GithubHelp logo

flow-wallet-api-demo's Introduction

Flow Wallet API Demo

This repository demonstrates basic usage of Wallet API using Docker.

Setup

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>

Running Wallet API

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.

Endpoints

Check out API Documentation for list of endpoints.

Version

curl http://localhost:3000/v1/debug

Create New Account

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.

Transactions

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){}}"}'

flow-wallet-api-demo's People

Contributors

nvdtf avatar

Stargazers

Greg Santos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.