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.
- 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
/wp-admin/options-general.php?page=web3-wallet-login
Get the wallet address of the current user.
This function retrieves the wallet address associated with the currently logged-in user. If no user is logged in, it returns null
.
$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.";
}
- 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 the balance of the current user.
This function retrieves the balance associated with the currently logged-in user. If no user is logged in, it returns null
.
$balance = get_current_user_balance();
if ($balance) {
echo "Balance: " . $balance;
} else {
echo "No balance found or user not logged in.";
}
- string|null: The balance of the current user, or
null
if no user is logged in or the balance is not found.
Get the airdrop information of the current user.
This function retrieves the airdrop information associated with the currently logged-in user. If no user is logged in, it returns null
.
$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.";
}
- 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.
Displays the Web3 Wallet Login button.
[web3_wallet_login_button redirection_url="/" button_text="Connect Wallet"]
This shortcode generates a button that allows users to log in using their Web3 wallet. When clicked, it initiates the Web3 wallet login process.
Displays the Web3 Wallet Logout button.
[web3_wallet_logout_button redirection_url="/" button_text="Logout"]
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.
Displays the wallet address of the current user.
[web3_wallet_address_display]
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.
Displays the balance of the current user.
[web3_wallet_balance_display]
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.
Generates a button to check a user's eligibility for an airdrop.
[web3_check_eligibility_button button_text="Check Eligibility"]
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.
Generates a button to claim an airdrop.
[web3_claim_airdrop_button button_text="Claim Airdrop"]
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.
Generates a form to transfer tokens to another address.
[web3_token_transfer button_text_transfer="Transfer" button_text_withdraw="Withdraw"]
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.
Claims tokens based on a Merkle proof.
root
(bytes32
): The Merkle root.amount
(uint256
): The amount to claim.proof
(bytes32[]
): The Merkle proof.
nonpayable
{
"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 tokens to another address.
to
(address
): The address to transfer tokens to.value
(uint256
): The amount of tokens to transfer.
nonpayable
{
"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"
}
Retrieve the airdrop information for a specific address.
- Method: GET
- URL:
/v1/airdrop/apply
- Parameters:
address
(string): The address to check for airdrop eligibility.
GET https://dev.flxdu.cn/chub/v1/airdrop/apply?address=0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
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"
}
]
}
}
Retrieve the contract address for the airdrop.
- Method: GET
- URL:
/v1/airdrop/contract_address
GET https://dev.flxdu.cn/chub/v1/airdrop/contract_address
{
"code": 0,
"message": "Success",
"error": "",
"data": {
"token": "0xYourTokenAddressHere",
"airdrop": "0xYourAirdropContractAddressHere",
"deployer": "0xYourDeployerWalletAddressHere"
}
}
Retrieve the token information for the airdrop.
- Method: GET
- URL:
/v1/airdrop/token_info
GET https://dev.flxdu.cn/chub/v1/airdrop/token_info
{
"code": 0,
"message": "Success",
"error": "",
"data": {
"name": "Chub Token",
"symbol": "Chub",
"decimals": 18,
"token_image": ""
}
}
Distribute the airdrop to the specified addresses. This endpoint is for testing purposes only.
- Method: POST
- URL:
/v1/airdrop/distribute
- Body: JSON object containing the addresses to distribute the airdrop to.
POST https://dev.flxdu.cn/chub/v1/airdrop/distribute
{
"code": 0,
"message": "Airdrop distributed successfully",
"error": ""
}
Withdraw the tokens to the user address.
- 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
{
"code": 0,
"message": "Success",
"error": "",
"data": "0xYourTransactionHash"
}
Retrieve network information.
- Method: GET
- URL:
/v1/airdrop/network
GET https://dev.flxdu.cn/chub/v1/airdrop/network
{
"code": 0,
"message": "Success",
"error": "",
"data": {
"rpc": "https://dev.flxdu.cn/ganache",
"id": 1337
}
}