Skip to content

Enable Ethereum Web3 Wallet Login for wordpress via this plugin.

License

Notifications You must be signed in to change notification settings

BTI-US/wordpress-web3-wallet-login

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

web3-wallet-login

This module allows for users to login via their web3 wallet.

Administrators can provide the ability to enable Web3 Wallet Login and set public addresses for any wordpress user account.

Once enabled, a user will see a button on the login page that will launch their web3 ethereum compatible wallet (ie metamask) and allow them to sign a message. Signing a message ensures the user is the owner of the address they are logging in with and does not compromise any account information or cost any gas fees.

Settings Screen 1 Settings Screen 2 Settings Screen 3 Settings Screen 4 Settings Screen 5 User Profile Screen Login Screen

Features

  • Web3 wallet login and logout via WalletConnect
  • Require message signature for verification
  • Ethereum network support
  • Get the Web3 wallet address of the current user
  • Get the balance of the current user
  • Transfer tokens to contract address or withdraw tokens
  • Enable Cloudflare Turnstile for human verification

Settings page

/wp-admin/options-general.php?page=web3-wallet-login

Interfaces

get_current_user_wallet_address()

Get the wallet address of the current user.

Description

This function retrieves the wallet address associated with the currently logged-in user. If no user is logged in, it returns null.

Usage

$wallet_address = get_current_user_wallet_address();
if ($wallet_address) {
    echo "Wallet Address: " . $wallet_address;
} else {
    echo "No wallet address found or user not logged in.";
}

Return

  • string|null: The wallet address of the current user, or null if no user is logged in or the wallet address is not found.

get_current_user_balance()

Get the balance of the current user.

Description

This function retrieves the balance associated with the currently logged-in user. If no user is logged in, it returns null.

Usage

$balance = get_current_user_balance();
if ($balance) {
    echo "Balance: " . $balance;
} else {
    echo "No balance found or user not logged in.";
}

Return

  • string|null: The balance of the current user, or null if no user is logged in or the balance is not found.

get_current_user_airdrop()

Get the airdrop information of the current user.

Description

This function retrieves the airdrop information associated with the currently logged-in user. If no user is logged in, it returns null.

Usage

$airdrop_info = get_current_user_airdrop();
if ($airdrop_info) {
    if ($airdrop_info['error']) {
        echo "Error: " . $airdrop_info['message'];
    } else {
        echo "Tree Root: " . $airdrop_info['tree_root'];
        echo "Proofs: " . json_encode($airdrop_info['proofs']);
        echo "Airdrop Count: " . $airdrop_info['airdrop_count'];
    }
} else {
    echo "No airdrop information found or user not logged in.";
}

Return

  • array|null: The airdrop information of the current user, or null if no user is logged in or the airdrop information is not found. The array contains:
    • error: A boolean indicating if there was an error.
    • message: A string message describing the error (if any).
    • tree_root: The tree root of the airdrop.
    • proofs: The proofs associated with the airdrop.
    • airdrop_count: The count of the airdrop.

Shortcodes

[web3_wallet_login_button]

Displays the Web3 Wallet Login button.

Usage

[web3_wallet_login_button redirection_url="/" button_text="Connect Wallet"]

Description

This shortcode generates a button that allows users to log in using their Web3 wallet. When clicked, it initiates the Web3 wallet login process.

[web3_wallet_logout_button]

Displays the Web3 Wallet Logout button.

Usage

[web3_wallet_logout_button redirection_url="/" button_text="Logout"]

Description

This shortcode generates a button that allows users to log out from their Web3 wallet. When clicked, it logs the user out of their Web3 wallet session.

[web3_wallet_address_display]

Displays the wallet address of the current user.

Usage

[web3_wallet_address_display]

Description

This shortcode displays the wallet address of the currently logged-in user. If the user is not logged in or the wallet address is not found, it shows an appropriate message.

[web3_wallet_balance_display]

Displays the balance of the current user.

Usage

[web3_wallet_balance_display]

Description

This shortcode displays the balance of the currently logged-in user. If the user is not logged in or the balance is not found, it shows an appropriate message.

[web3_check_eligibility_button]

Generates a button to check a user's eligibility for an airdrop.

Usage

[web3_check_eligibility_button button_text="Check Eligibility"]

Description

This shortcode generates a button that allows users to check their eligibility for an airdrop. When clicked, it triggers an AJAX request to check the eligibility and displays the result.

[web3_claim_airdrop_button]

Generates a button to claim an airdrop.

Usage

[web3_claim_airdrop_button button_text="Claim Airdrop"]

Description

This shortcode generates a button that allows users to claim an airdrop. When clicked, it triggers an AJAX request to claim the airdrop and displays the result.

[web3_token_transfer]

Generates a form to transfer tokens to another address.

Usage

[web3_token_transfer button_text_transfer="Transfer" button_text_withdraw="Withdraw"]

Description

This shortcode generates a form that allows users to transfer tokens or withdraw tokens to the contract address. The form includes fields for the amount of tokens to transfer.

Blockchain ABI

claim(root, amount, proof)

Claims tokens based on a Merkle proof.

Parameters

  • root (bytes32): The Merkle root.
  • amount (uint256): The amount to claim.
  • proof (bytes32[]): The Merkle proof.

Mutability

nonpayable

ABI Code

{
    "inputs": [
        {
            "internalType": "bytes32",
            "name": "root",
            "type": "bytes32"
        },
        {
            "internalType": "uint256",
            "name": "amount",
            "type": "uint256"
        },
        {
            "internalType": "bytes32[]",
            "name": "proof",
            "type": "bytes32[]"
        }
    ],
    "name": "claim",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
}

transfer(to, value)

Transfer tokens to another address.

Parameters

  • to (address): The address to transfer tokens to.
  • value (uint256): The amount of tokens to transfer.

Mutability

nonpayable

ABI Code

{
    "inputs": [
        {
            "internalType":"address",
            "name":"to",
            "type":"address"
        },
        {
            "internalType":"uint256",
            "name":"value",
            "type":"uint256"
        }
    ],
    "name":"transfer",
    "outputs": [
        {
            "internalType":"bool",
            "name":"",
            "type":"bool"
        }
    ],
    "stateMutability":"nonpayable",
    "type":"function"
}

API Endpoints

GET /v1/airdrop/apply

Retrieve the airdrop information for a specific address.

Request

  • Method: GET
  • URL: /v1/airdrop/apply
  • Parameters:
    • address (string): The address to check for airdrop eligibility.

Example

GET https://dev.flxdu.cn/chub/v1/airdrop/apply?address=0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc

Response

If the address is eligible for an airdrop, the response will include the airdrop details. If the airdrop has not been distributed yet, tree_root and proofs will be empty.

{
    "code": 0,
    "message": "Success",
    "error": "",
    "data": {
        "address": "0x9965507d1A55BCc2695C58Ba16Fb37d819b0A4dd",
        "airdrops": [
            {
                "airdrop_count": 100000,
                "tree_root": "",
                "proofs": [],
                "scheduled_delivery": "2025-01-25T13:00:00Z"
            }
        ]
    }
}

If the airdrop has been distributed, tree_root and proofs will contain the relevant data.

{
    "code": 0,
    "message": "Success",
    "error": "",
    "data": {
        "address": "0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc",
        "airdrops": [
            {
                "airdrop_count": 100000,
                "tree_root": "6a0776823faf25f7b9255a280a45fc52bb8c31a702287e667dbb756405f9bc15",
                "proofs": [
                    "47c0068c1b31647cdc88fca6430e9a0e45fe8d9830a91bea2037dc4a5e0f3d58",
                    "2291151a59e56d010f216945e47ab9ece77a8469537a90ac77077cb6bf8a6465",
                    "7dd3a22b09646af49767248d7525eb8795d9fec5b31cc1f0db9108e0dde0b19b"
                ],
                "scheduled_delivery": "2025-01-24T13:00:00Z"
            }
        ]
    }
}

GET /v1/airdrop/contract_address

Retrieve the contract address for the airdrop.

Request

  • Method: GET
  • URL: /v1/airdrop/contract_address

Example

GET https://dev.flxdu.cn/chub/v1/airdrop/contract_address

Response

{
    "code": 0,
    "message": "Success",
    "error": "",
    "data": {
        "token": "0xYourTokenAddressHere",
        "airdrop": "0xYourAirdropContractAddressHere",
        "deployer": "0xYourDeployerWalletAddressHere"
    }
}

GET /v1/airdrop/token_info

Retrieve the token information for the airdrop.

Request

  • Method: GET
  • URL: /v1/airdrop/token_info

Example

GET https://dev.flxdu.cn/chub/v1/airdrop/token_info

Response

{
    "code": 0,
    "message": "Success",
    "error": "",
    "data": {
        "name": "Chub Token",
        "symbol": "Chub",
        "decimals": 18,
        "token_image": ""
    }
}

POST /v1/airdrop/distribute (Test Only)

Distribute the airdrop to the specified addresses. This endpoint is for testing purposes only.

Request

  • Method: POST
  • URL: /v1/airdrop/distribute
  • Body: JSON object containing the addresses to distribute the airdrop to.

Example

POST https://dev.flxdu.cn/chub/v1/airdrop/distribute

Response

{
    "code": 0,
    "message": "Airdrop distributed successfully",
    "error": ""
}

POST /v1/deposit/withdraw

Withdraw the tokens to the user address.

Request

  • Method: POST
  • URL: /v1/deposit/withdraw
  • Body: JSON object containing the amount to withdraw.
{
    "address": "0xYourEthereumAddress",
    "amount": 100
}

#### Example

```bash
POST https://dev.flxdu.cn/chub/v1/deposit/withdraw

Response

{
    "code": 0,
    "message": "Success",
    "error": "",
    "data": "0xYourTransactionHash"
}

GET /v1/airdrop/network

Retrieve network information.

Request

  • Method: GET
  • URL: /v1/airdrop/network

Example

GET https://dev.flxdu.cn/chub/v1/airdrop/network

Response

{
    "code": 0,
    "message": "Success",
    "error": "",
    "data": {
        "rpc": "https://dev.flxdu.cn/ganache",
        "id": 1337
    }
}

About

Enable Ethereum Web3 Wallet Login for wordpress via this plugin.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published