Git Product home page Git Product logo

two1-sell-boilerplate's Introduction

21 sell Machine-Payable Container Boilerplate

This repository contains a runnable boilerplate for a machine-payable 21 sell container that returns the string 'Hello, world' for every 21 buy request on its /hello route. If you do not have a 21 account, please go to https://21.co to sign up.

Go through the 21 sell tutorial, and follow the steps in the "Quickstart" section below to get to know the lifecycle of a 21 sell container. Then continue with the examples in the "Modifying the Boilerplate" section to customize the boilerplate to your specific application.

Quickstart

Clone the boilerplate repository

with HTTPS

git clone https://github.com/21dotco/two1-sell-boilerplate.git

with SSH (make sure you've generated and added your SSH public key to github)

git clone [email protected]:21dotco/two1-sell-boilerplate.git

Building, tagging, and pushing to your docker repo

Make sure you've installed Docker on your system. To build the image as <dockerhub_username>/hello21 locally, do

cd two1-sell-boilerplate
docker build -t <dockerhub_username>/hello21 .

Note: you may need to execute the Docker commands with sudo.

Optionally, if you have a Docker Hub account, you can upload the image so that it is available on other machines (make sure you've completed the steps here)

docker login
docker push <dockerhub_username>/hello21

Registering your repo with 21 sell

To register your service with 21 sell as hello21 so that it'll be listed under 21 list, 21 status --detail and started with 21 sell start --all

21 sell add hello21 <dockerhub_username>/hello21

To see currently registered repos

21 sell list

Starting your 21 sell container

While running the following command, make sure to confirm that you want to publish so we can buy from the container

21 sell start hello21

Your container will be started under the name sell_hello21

Buying from your 21 sell container

Visit 21.co/<your-21.co-username> to see the service you've just published. It should have "Hello, World!" as the title.

To buy from your own service, look for the command under your service's usage tab formatted as such:

21 buy <your-21.co-username>/hello-world<random-identifier>/hello21/hello

To check the balance of your 21 sell container

21 sell status --detail

Stopping your 21 sell container

21 sell stop hello21

You can also unpublish your 21 sell service

21 publish list  # copy the four letter ID for your service
21 publish remove <service-id>

Modifying the Boilerplate

Modifying the boilerplate to suite your specific application will typically involve modifying the:

  • server.py for server logic (see here for information on flask and here for relevant information on two1)
  • setup.py for module dependencies and metadata (see here for more information)
  • manifest.yaml for metadata that will be displayed on the 21 marketplace (see here for more information)

Example 1: Modifying the route of your machine-payable endpoint

In server.py, find the line

@app.route('/hello')

and replace hello with the desired route

Note: You may want to change the function name on the line def hello(): as well

You also want to modify the x-21-quick-buy field in manifest.yaml to reflect this change

info:
  ...
  x-21-quick-buy: "$ 21 buy http://%s:%s/%s/hello"
  ...

by replacing hello with the aforementioned desired route

Note: The three %-style formatting placeholders are formatted with the ZeroTier IP and port number of your payment server, and the name of your service respectively.

Example 2: Change the price of your machine-payable endpoint

In server.py, find the line

@payment.required(5000, server_url=os.environ.get("PAYMENT_SERVER_IP", None))

and replace 5000 with the desired price in satoshis

You also want to modify manifest.yaml to reflect this change

info:
  ...
  x-21-total-price:
    min: 5000
    max: 5000
  ...

by replacing the two 5000's with the aforementioned desired price in satoshis

Example 3: Adding an additional dependency

If you've modified the server logic under server.py have imported additional dependencies, make sure to include them in setup.py

For a dependency Foo at version 2.1.0, make sure it appears under the install_requires kwarg to setuptools.setup

setuptools.setup(
	...
    install_requires=[  # list all dependencies for your project here
        ...
        "Foo=2.1.0",
        ...
    ],
    ...
)

two1-sell-boilerplate's People

Contributors

jagranata avatar harding avatar dongcarl avatar wbnns avatar

Watchers

James Cloos avatar Hoang Manh Phu 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.