djoser-web3


Namedjoser-web3 JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://boomslag.com
SummaryExtension of Djoser package that includes Web3 Authentication for Django Rest Framework
upload_time2023-01-05 12:55:57
maintainer
docs_urlNone
authorBoomslag
requires_python
licenseMIT
keywords djangorestframework web3 ethereum
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Djoser Web 3
##################################


**Getting Started**
********************

To get started with Djoser in Django, you will need to install the Djoser library and configure it in your Django project. Here are the steps you can follow:

**Step 1**. Install the Djoser library using pip:

    .. code-block:: python

        pip install djoser djoser-web3

**Step 2**. Add **`djoser`** and **`djoser-web3`** to the **INSTALLED_APPS** list in your Django project's **`settings.py`** file:

    .. code-block:: python

        DJANGO_APPS = [
            'django.contrib.admin',
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',
            'django.contrib.messages',
            'django.contrib.staticfiles',
        ]

        PROJECT_APPS = [
        ]

        THIRD_PARTY_APPS = [

            'djoser', 
            'djoser-web3',

            'rest_framework',
            'rest_framework_simplejwt',
            'rest_framework_simplejwt.token_blacklist',

            'social_django',
        ]

        INSTALLED_APPS = DJANGO_APPS + PROJECT_APPS + THIRD_PARTY_APPS


**Step 3 (Optional)**. Configure social_django middleware (Optional if you decide to use Social Auth)
   
    .. code-block:: python

        MIDDLEWARE = [

            'social_django.middleware.SocialAuthExceptionMiddleware',

            'django.middleware.security.SecurityMiddleware',
            'django.contrib.sessions.middleware.SessionMiddleware',
            'django.middleware.common.CommonMiddleware',
            'django.middleware.csrf.CsrfViewMiddleware',
            'django.contrib.auth.middleware.AuthenticationMiddleware',
            'django.contrib.messages.middleware.MessageMiddleware',
            'django.middleware.clickjacking.XFrameOptionsMiddleware',
        ]


**Step 4 (Optional)**. Copy paste this password hashers in settings.py

    .. code-block:: python

        # Password validation
        PASSWORD_HASHERS = [
            "django.contrib.auth.hashers.Argon2PasswordHasher",
            "django.contrib.auth.hashers.PBKDF2PasswordHasher",
            "django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
            "django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
        ]


**Step 5**. Configure Settings.py to work with REST_FRAMEWORK, DJOSER and SIMPLE_JWT. Here i show a simple example of how this could be achieved.

    .. code-block:: python
        
        # REST FRAMEWORK
        REST_FRAMEWORK = {
            'DEFAULT_PERMISSION_CLASSES': [
                'rest_framework.permissions.IsAuthenticatedOrReadOnly'
            ],
            'DEFAULT_AUTHENTICATION_CLASSES': (
                'rest_framework_simplejwt.authentication.JWTAuthentication',
            ),
        }
        #Authentication backends
        AUTHENTICATION_BACKENDS = (
            'social_core.backends.google.GoogleOAuth2',
            'social_core.backends.facebook.FacebookOAuth2',
            'django.contrib.auth.backends.ModelBackend',
        )
        #Simple JWT
        SIMPLE_JWT = {
            'AUTH_HEADER_TYPES': ('JWT', ),
            'ACCESS_TOKEN_LIFETIME': timedelta(minutes=10080),
            'REFRESH_TOKEN_LIFETIME': timedelta(days=30),
            'ROTATE_REFRESFH_TOKENS':True,
            'BLACKLIST_AFTER_ROTATION': True,
            'AUTH_TOKEN_CLASSES': (
                'rest_framework_simplejwt.tokens.AccessToken',
            )
        }

        #Djoser
        DJOSER = {
            'LOGIN_FIELD': 'email',
            'USER_CREATE_PASSWORD_RETYPE': True,
            'USERNAME_CHANGED_EMAIL_CONFIRMATION': True,
            'PASSWORD_CHANGED_EMAIL_CONFIRMATION': True,
            'SEND_CONFIRMATION_EMAIL': True,
            'SEND_ACTIVATION_EMAIL': True,
            'SET_USERNAME_RETYPE': True,
            'PASSWORD_RESET_CONFIRM_URL': 'password/reset/confirm/{uid}/{token}',
            'SET_PASSWORD_RETYPE': True,
            'PASSWORD_RESET_CONFIRM_RETYPE': True,
            'USERNAME_RESET_CONFIRM_URL': 'email/reset/confirm/{uid}/{token}',
            'ACTIVATION_URL': 'activate/{uid}/{token}',
            'SOCIAL_AUTH_TOKEN_STRATEGY': 'djoser.social.token.jwt.TokenStrategy',
            'SOCIAL_AUTH_ALLOWED_REDIRECT_URIS': ['http://localhost:8000/google', 'http://localhost:8000/facebook'],
            'SERIALIZERS': {
                'user_create': 'apps.user.serializers.UserSerializer',
                'user': 'apps.user.serializers.UserSerializer',
                'current_user': 'apps.user.serializers.UserSerializer',
                'user_delete': 'djoser.serializers.UserDeleteSerializer',
            },
        }

        SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=os.environ.get('SOCIAL_AUTH_GOOGLE_OAUTH2_KEY')
        SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=os.environ.get('SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET')
        SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
            'https://www.googleapis.com/auth/userinfo.email',
            'https://www.googleapis.com/auth/userinfo.profile',
            'openid'
        ]
        SOCIAL_AUTH_GOOGLE_OAUTH2_EXTRA_DATA = ['first_name', 'last_name']

        SOCIAL_AUTH_FACEBOOK_KEY = os.environ.get('SOCIAL_AUTH_FACEBOOK_KEY')
        SOCIAL_AUTH_FACEBOOK_SECRET = os.environ.get('SOCIAL_AUTH_FACEBOOK_SECRET')
        SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
        SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {'fields': 'email, first_name, last_name'}

You may want to explore djoser's documentation to understand in more detail each field and the possible parameters you might want to use.


**Step 6**. Include the Djoser URL patterns in your project's root urls.py file:

    .. code-block:: python

        from django.urls import path, include
        from django.contrib import admin
        from django.conf import settings
        from django.conf.urls.static import static

        urlpatterns = [
            path('auth/', include('djoser.urls')),
            path('auth/', include('djoser.urls.jwt')),
            path('auth/', include('djoser.social.urls')),

            path('admin/', admin.site.urls),
        ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


**Step 7**. Include you **ACTIVE_CAMPAIGN** api key and user information in your **`settings.py`**, this is so users that register will automatically be added to your marketing pipeline.

    .. code-block:: python

        ACTIVE_CAMPAIGN_URL = os.environ.get('ACTIVE_CAMPAIGN_URL')
        ACTIVE_CAMPAIGN_KEY = os.environ.get('ACTIVE_CAMPAIGN_KEY')

**Step 8**. Install **Stripe** package. This is so users that register on your site will also get added to your stripe customer list and stripe connect sellers.

    .. code-block:: python

        pip install stripe

**Step 9**. Get the stripe api keys and create a stripe webhook (just a demo one, you may add any events you like), add those values to the **`settings.py`**.

    .. code-block:: python

        STRIPE_PUBLIC_KEY = os.environ.get('STRIPE_PUBLIC_KEY_DEV')
        STRIPE_SECRET_KEY = os.environ.get('STRIPE_SECRET_KEY_DEV')
        STRIPE_WEBHOOK_SECRET= os.environ.get('STRIPE_WEBHOOK_SECRET_DEV')

**Step 10**. Now declare the custom user model in settings.py.

    .. code-block:: python

        AUTH_USER_MODEL = 'djoser_web3.UserAccount'

**Step 11**. Configure email backends to send email.

    .. code-block:: python

        EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'

**Step 12**. Run the migrations to create the necessary database tables

    .. code-block:: python

        python manage.py makemigrations
        python manage.py migrate

* With this basic setup you have a website that is capable of registering users while at the same time it: 

    #. Creates a User Profile
    #. User Ethereum Wallet
    #. User Stripe Account
    #. User Stripe Connect Account
    #. Adds user to marketing list

You may now extend any model from djoser_web3 and create your views and urls.

Test the Djoser authentication views by sending HTTP requests to the endpoint URLs. For example, you can use a tool like curl to send a POST request to the /auth/users/ endpoint to create a new user.

**Example**
============

Here's an example json object to create a new user.

In order to register using a frontend framework like React or Angular, you may send a post request with this format:

    .. code-block:: json

        {
            "email":"test@gmail.com",
            "username":"test",
            "agreed":"True",
            "first_name":"Test",
            "last_name":"test",
            "password":"1234!qwer",
            "re_password":"1234!qwer"
        }

Notice this model is using an "Agreed" field, this field will decide wether the user wants to be added to the marketing llist and receive automated emails.

This should create a new user with the specified username, email, and password. You can then use the Djoser views to authenticate users, reset passwords, etc.

For more information, you can **refer to the Djoser documentation**: **`https://djoser.readthedocs.io/en/latest/index.html`**


**Sending Ethereum Transactions**
*********************************

To retrieve the private key, you will need to store the original private key somewhere where it can be accessed later. 

One way to do this is to store the private key in a separate database table with a reference to the hashed private key. 

Then, you can retrieve the original private key by querying the database using the hashed private key as a lookup key.

Here's an example of how you can retrieve the original private key:

    .. code-block:: python

        def get_private_key(private_key_hash):
            # Query the database for the wallet with the matching private key hash
            wallet = Wallet.objects.get(private_key_hash=private_key_hash)
            
            # Return the private key
            return wallet.private_key

You can then use this function to retrieve the private key whenever you need it for a transaction.

To access the private key and use it to make an Ethereum transaction, you will need to retrieve the original private key using the hashed private key as a lookup key.

Here's an example of how you can retrieve the private key and use it to sign and send a transaction:

    .. code-block::python

        from djoser_web3.utils import get_private_key

        def send_transaction(private_key_hash, to, value):
            # Retrieve the private key using the private_key_hash
            private_key = get_private_key(wallet.private_key_hash)

            # Set up the Ethereum transaction
            tx = {
                'to': to,
                'value': value,
                'gas': 2000000,
                'gasPrice': 234567897654321,
                'nonce': 0,
                'chainId': 1
            }

            # Sign and send the transaction
            signed_tx = acct.sign_transaction(tx)
            tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)

            return tx_hash

You can then call this function to send a transaction by passing in the hashed private key, the recipient address, and the value of the transaction the get_private_key function that I provided is the one you will use to retrieve the original private key using the hashed private key as a lookup key.

It is a good idea to store this function in a separate file so that you can reuse it in different parts of your project. You can then import the function into any module that needs to use it by using the import statement.

For example, you could create a utils.py file in your project and put the get_private_key function in that file. Then, in any other module where you want to use the function, you can do:

    .. code-block:: python
    
        from utils import get_private_key

        # Use the get_private_key function
        private_key = get_private_key(private_key_hash)

            

Raw data

            {
    "_id": null,
    "home_page": "https://boomslag.com",
    "name": "djoser-web3",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "support@boomslag.com",
    "keywords": "djangorestframework web3 ethereum",
    "author": "Boomslag",
    "author_email": "mail@boomslag.com",
    "download_url": "https://files.pythonhosted.org/packages/3c/3c/1e36178f5ec54094560f76052ced7304dc6a540ac996cd74e77cf13b7a02/djoser_web3-0.0.2.tar.gz",
    "platform": null,
    "description": "Djoser Web 3\r\n##################################\r\n\r\n\r\n**Getting Started**\r\n********************\r\n\r\nTo get started with Djoser in Django, you will need to install the Djoser library and configure it in your Django project. Here are the steps you can follow:\r\n\r\n**Step 1**. Install the Djoser library using pip:\r\n\r\n    .. code-block:: python\r\n\r\n        pip install djoser djoser-web3\r\n\r\n**Step 2**. Add **`djoser`** and **`djoser-web3`** to the **INSTALLED_APPS** list in your Django project's **`settings.py`** file:\r\n\r\n    .. code-block:: python\r\n\r\n        DJANGO_APPS = [\r\n            'django.contrib.admin',\r\n            'django.contrib.auth',\r\n            'django.contrib.contenttypes',\r\n            'django.contrib.sessions',\r\n            'django.contrib.messages',\r\n            'django.contrib.staticfiles',\r\n        ]\r\n\r\n        PROJECT_APPS = [\r\n        ]\r\n\r\n        THIRD_PARTY_APPS = [\r\n\r\n            'djoser', \r\n            'djoser-web3',\r\n\r\n            'rest_framework',\r\n            'rest_framework_simplejwt',\r\n            'rest_framework_simplejwt.token_blacklist',\r\n\r\n            'social_django',\r\n        ]\r\n\r\n        INSTALLED_APPS = DJANGO_APPS + PROJECT_APPS + THIRD_PARTY_APPS\r\n\r\n\r\n**Step 3 (Optional)**. Configure social_django middleware (Optional if you decide to use Social Auth)\r\n   \r\n    .. code-block:: python\r\n\r\n        MIDDLEWARE = [\r\n\r\n            'social_django.middleware.SocialAuthExceptionMiddleware',\r\n\r\n            'django.middleware.security.SecurityMiddleware',\r\n            'django.contrib.sessions.middleware.SessionMiddleware',\r\n            'django.middleware.common.CommonMiddleware',\r\n            'django.middleware.csrf.CsrfViewMiddleware',\r\n            'django.contrib.auth.middleware.AuthenticationMiddleware',\r\n            'django.contrib.messages.middleware.MessageMiddleware',\r\n            'django.middleware.clickjacking.XFrameOptionsMiddleware',\r\n        ]\r\n\r\n\r\n**Step 4 (Optional)**. Copy paste this password hashers in settings.py\r\n\r\n    .. code-block:: python\r\n\r\n        # Password validation\r\n        PASSWORD_HASHERS = [\r\n            \"django.contrib.auth.hashers.Argon2PasswordHasher\",\r\n            \"django.contrib.auth.hashers.PBKDF2PasswordHasher\",\r\n            \"django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher\",\r\n            \"django.contrib.auth.hashers.BCryptSHA256PasswordHasher\",\r\n        ]\r\n\r\n\r\n**Step 5**. Configure Settings.py to work with REST_FRAMEWORK, DJOSER and SIMPLE_JWT. Here i show a simple example of how this could be achieved.\r\n\r\n    .. code-block:: python\r\n        \r\n        # REST FRAMEWORK\r\n        REST_FRAMEWORK = {\r\n            'DEFAULT_PERMISSION_CLASSES': [\r\n                'rest_framework.permissions.IsAuthenticatedOrReadOnly'\r\n            ],\r\n            'DEFAULT_AUTHENTICATION_CLASSES': (\r\n                'rest_framework_simplejwt.authentication.JWTAuthentication',\r\n            ),\r\n        }\r\n        #Authentication backends\r\n        AUTHENTICATION_BACKENDS = (\r\n            'social_core.backends.google.GoogleOAuth2',\r\n            'social_core.backends.facebook.FacebookOAuth2',\r\n            'django.contrib.auth.backends.ModelBackend',\r\n        )\r\n        #Simple JWT\r\n        SIMPLE_JWT = {\r\n            'AUTH_HEADER_TYPES': ('JWT', ),\r\n            'ACCESS_TOKEN_LIFETIME': timedelta(minutes=10080),\r\n            'REFRESH_TOKEN_LIFETIME': timedelta(days=30),\r\n            'ROTATE_REFRESFH_TOKENS':True,\r\n            'BLACKLIST_AFTER_ROTATION': True,\r\n            'AUTH_TOKEN_CLASSES': (\r\n                'rest_framework_simplejwt.tokens.AccessToken',\r\n            )\r\n        }\r\n\r\n        #Djoser\r\n        DJOSER = {\r\n            'LOGIN_FIELD': 'email',\r\n            'USER_CREATE_PASSWORD_RETYPE': True,\r\n            'USERNAME_CHANGED_EMAIL_CONFIRMATION': True,\r\n            'PASSWORD_CHANGED_EMAIL_CONFIRMATION': True,\r\n            'SEND_CONFIRMATION_EMAIL': True,\r\n            'SEND_ACTIVATION_EMAIL': True,\r\n            'SET_USERNAME_RETYPE': True,\r\n            'PASSWORD_RESET_CONFIRM_URL': 'password/reset/confirm/{uid}/{token}',\r\n            'SET_PASSWORD_RETYPE': True,\r\n            'PASSWORD_RESET_CONFIRM_RETYPE': True,\r\n            'USERNAME_RESET_CONFIRM_URL': 'email/reset/confirm/{uid}/{token}',\r\n            'ACTIVATION_URL': 'activate/{uid}/{token}',\r\n            'SOCIAL_AUTH_TOKEN_STRATEGY': 'djoser.social.token.jwt.TokenStrategy',\r\n            'SOCIAL_AUTH_ALLOWED_REDIRECT_URIS': ['http://localhost:8000/google', 'http://localhost:8000/facebook'],\r\n            'SERIALIZERS': {\r\n                'user_create': 'apps.user.serializers.UserSerializer',\r\n                'user': 'apps.user.serializers.UserSerializer',\r\n                'current_user': 'apps.user.serializers.UserSerializer',\r\n                'user_delete': 'djoser.serializers.UserDeleteSerializer',\r\n            },\r\n        }\r\n\r\n        SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=os.environ.get('SOCIAL_AUTH_GOOGLE_OAUTH2_KEY')\r\n        SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=os.environ.get('SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET')\r\n        SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [\r\n            'https://www.googleapis.com/auth/userinfo.email',\r\n            'https://www.googleapis.com/auth/userinfo.profile',\r\n            'openid'\r\n        ]\r\n        SOCIAL_AUTH_GOOGLE_OAUTH2_EXTRA_DATA = ['first_name', 'last_name']\r\n\r\n        SOCIAL_AUTH_FACEBOOK_KEY = os.environ.get('SOCIAL_AUTH_FACEBOOK_KEY')\r\n        SOCIAL_AUTH_FACEBOOK_SECRET = os.environ.get('SOCIAL_AUTH_FACEBOOK_SECRET')\r\n        SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']\r\n        SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {'fields': 'email, first_name, last_name'}\r\n\r\nYou may want to explore djoser's documentation to understand in more detail each field and the possible parameters you might want to use.\r\n\r\n\r\n**Step 6**. Include the Djoser URL patterns in your project's root urls.py file:\r\n\r\n    .. code-block:: python\r\n\r\n        from django.urls import path, include\r\n        from django.contrib import admin\r\n        from django.conf import settings\r\n        from django.conf.urls.static import static\r\n\r\n        urlpatterns = [\r\n            path('auth/', include('djoser.urls')),\r\n            path('auth/', include('djoser.urls.jwt')),\r\n            path('auth/', include('djoser.social.urls')),\r\n\r\n            path('admin/', admin.site.urls),\r\n        ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)\r\n\r\n\r\n**Step 7**. Include you **ACTIVE_CAMPAIGN** api key and user information in your **`settings.py`**, this is so users that register will automatically be added to your marketing pipeline.\r\n\r\n    .. code-block:: python\r\n\r\n        ACTIVE_CAMPAIGN_URL = os.environ.get('ACTIVE_CAMPAIGN_URL')\r\n        ACTIVE_CAMPAIGN_KEY = os.environ.get('ACTIVE_CAMPAIGN_KEY')\r\n\r\n**Step 8**. Install **Stripe** package. This is so users that register on your site will also get added to your stripe customer list and stripe connect sellers.\r\n\r\n    .. code-block:: python\r\n\r\n        pip install stripe\r\n\r\n**Step 9**. Get the stripe api keys and create a stripe webhook (just a demo one, you may add any events you like), add those values to the **`settings.py`**.\r\n\r\n    .. code-block:: python\r\n\r\n        STRIPE_PUBLIC_KEY = os.environ.get('STRIPE_PUBLIC_KEY_DEV')\r\n        STRIPE_SECRET_KEY = os.environ.get('STRIPE_SECRET_KEY_DEV')\r\n        STRIPE_WEBHOOK_SECRET= os.environ.get('STRIPE_WEBHOOK_SECRET_DEV')\r\n\r\n**Step 10**. Now declare the custom user model in settings.py.\r\n\r\n    .. code-block:: python\r\n\r\n        AUTH_USER_MODEL = 'djoser_web3.UserAccount'\r\n\r\n**Step 11**. Configure email backends to send email.\r\n\r\n    .. code-block:: python\r\n\r\n        EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend'\r\n\r\n**Step 12**. Run the migrations to create the necessary database tables\r\n\r\n    .. code-block:: python\r\n\r\n        python manage.py makemigrations\r\n        python manage.py migrate\r\n\r\n* With this basic setup you have a website that is capable of registering users while at the same time it: \r\n\r\n    #. Creates a User Profile\r\n    #. User Ethereum Wallet\r\n    #. User Stripe Account\r\n    #. User Stripe Connect Account\r\n    #. Adds user to marketing list\r\n\r\nYou may now extend any model from djoser_web3 and create your views and urls.\r\n\r\nTest the Djoser authentication views by sending HTTP requests to the endpoint URLs. For example, you can use a tool like curl to send a POST request to the /auth/users/ endpoint to create a new user.\r\n\r\n**Example**\r\n============\r\n\r\nHere's an example json object to create a new user.\r\n\r\nIn order to register using a frontend framework like React or Angular, you may send a post request with this format:\r\n\r\n    .. code-block:: json\r\n\r\n        {\r\n            \"email\":\"test@gmail.com\",\r\n            \"username\":\"test\",\r\n            \"agreed\":\"True\",\r\n            \"first_name\":\"Test\",\r\n            \"last_name\":\"test\",\r\n            \"password\":\"1234!qwer\",\r\n            \"re_password\":\"1234!qwer\"\r\n        }\r\n\r\nNotice this model is using an \"Agreed\" field, this field will decide wether the user wants to be added to the marketing llist and receive automated emails.\r\n\r\nThis should create a new user with the specified username, email, and password. You can then use the Djoser views to authenticate users, reset passwords, etc.\r\n\r\nFor more information, you can **refer to the Djoser documentation**: **`https://djoser.readthedocs.io/en/latest/index.html`**\r\n\r\n\r\n**Sending Ethereum Transactions**\r\n*********************************\r\n\r\nTo retrieve the private key, you will need to store the original private key somewhere where it can be accessed later. \r\n\r\nOne way to do this is to store the private key in a separate database table with a reference to the hashed private key. \r\n\r\nThen, you can retrieve the original private key by querying the database using the hashed private key as a lookup key.\r\n\r\nHere's an example of how you can retrieve the original private key:\r\n\r\n    .. code-block:: python\r\n\r\n        def get_private_key(private_key_hash):\r\n            # Query the database for the wallet with the matching private key hash\r\n            wallet = Wallet.objects.get(private_key_hash=private_key_hash)\r\n            \r\n            # Return the private key\r\n            return wallet.private_key\r\n\r\nYou can then use this function to retrieve the private key whenever you need it for a transaction.\r\n\r\nTo access the private key and use it to make an Ethereum transaction, you will need to retrieve the original private key using the hashed private key as a lookup key.\r\n\r\nHere's an example of how you can retrieve the private key and use it to sign and send a transaction:\r\n\r\n    .. code-block::python\r\n\r\n        from djoser_web3.utils import get_private_key\r\n\r\n        def send_transaction(private_key_hash, to, value):\r\n            # Retrieve the private key using the private_key_hash\r\n            private_key = get_private_key(wallet.private_key_hash)\r\n\r\n            # Set up the Ethereum transaction\r\n            tx = {\r\n                'to': to,\r\n                'value': value,\r\n                'gas': 2000000,\r\n                'gasPrice': 234567897654321,\r\n                'nonce': 0,\r\n                'chainId': 1\r\n            }\r\n\r\n            # Sign and send the transaction\r\n            signed_tx = acct.sign_transaction(tx)\r\n            tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)\r\n\r\n            return tx_hash\r\n\r\nYou can then call this function to send a transaction by passing in the hashed private key, the recipient address, and the value of the transaction the get_private_key function that I provided is the one you will use to retrieve the original private key using the hashed private key as a lookup key.\r\n\r\nIt is a good idea to store this function in a separate file so that you can reuse it in different parts of your project. You can then import the function into any module that needs to use it by using the import statement.\r\n\r\nFor example, you could create a utils.py file in your project and put the get_private_key function in that file. Then, in any other module where you want to use the function, you can do:\r\n\r\n    .. code-block:: python\r\n    \r\n        from utils import get_private_key\r\n\r\n        # Use the get_private_key function\r\n        private_key = get_private_key(private_key_hash)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Extension of Djoser package that includes Web3 Authentication for Django Rest Framework",
    "version": "0.0.2",
    "split_keywords": [
        "djangorestframework",
        "web3",
        "ethereum"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cfa07a8c82d1d0b489743be3d5aa3905146d067d4a984ca9dd551964d31a6fae",
                "md5": "a4bd0217c3fc667de7a663c5b1d2c1cc",
                "sha256": "5b39307833a0fff3372e314b19750e450ca47549e56f0558dfea8c1e0e98b883"
            },
            "downloads": -1,
            "filename": "djoser_web3-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a4bd0217c3fc667de7a663c5b1d2c1cc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10253,
            "upload_time": "2023-01-05T12:55:55",
            "upload_time_iso_8601": "2023-01-05T12:55:55.764367Z",
            "url": "https://files.pythonhosted.org/packages/cf/a0/7a8c82d1d0b489743be3d5aa3905146d067d4a984ca9dd551964d31a6fae/djoser_web3-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c3c1e36178f5ec54094560f76052ced7304dc6a540ac996cd74e77cf13b7a02",
                "md5": "547d22bf91593663099dbd4153749ef1",
                "sha256": "1b176048ade17ce2e3ad1de553637a9d63753445178c5938a83fe4b01911c7a5"
            },
            "downloads": -1,
            "filename": "djoser_web3-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "547d22bf91593663099dbd4153749ef1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12908,
            "upload_time": "2023-01-05T12:55:57",
            "upload_time_iso_8601": "2023-01-05T12:55:57.164353Z",
            "url": "https://files.pythonhosted.org/packages/3c/3c/1e36178f5ec54094560f76052ced7304dc6a540ac996cd74e77cf13b7a02/djoser_web3-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-05 12:55:57",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "djoser-web3"
}
        
Elapsed time: 0.05560s