Moving funds to/from card
Precondition:
• An account must be created on the Wirex Pay Chain.
• A user entity must be created, with KYC completed and the phone number confirmed.
• A card in an active status is available.
Abstract:
When a Wirex Pay Card is issued, it is linked to a unique, dedicated wallet that operates independently from the user’s primary wallet obtained during on-chain registration. The card’s transactions, including payments and withdrawals, are managed from this dedicated wallet balance. This guide explains how to replenish the card balance by transferring funds from the user’s wallet to the card wallet and outlines the process for withdrawing funds from the card balance.
Step 1: Replenish Card Balance
To add funds to the card wallet, follow these steps:
- Obtain the Card Wallet Address:
• Use the relevant Get cardsAPI endpoint to retrieve the specific address of the card wallet. This endpoint provides essential information, including the card wallet address associated with the Wirex Pay Card. - Perform On-Chain Deposit:
• Once you have the card wallet address, initiate an on-chain transfer from the user’s primary wallet to the card wallet. This deposit increases the balance available for card transactions and allows the cardholder to use the card for payments. - Confirm Deposit:
• Wait for transaction confirmation to ensure that the card wallet balance has been updated. Once confirmed, these funds are ready for use in card transactions.
Step 2: Withdraw from Card Balance
To withdraw funds from the card balance and transfer them back to the user’s main wallet or another specified address, interact with the Card smart contract using an ABI call.
ABI transfer
{
"inputs": [
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
Contract address: card wallet address from Get cards.
Token addresses presented at Useful links.
- Initiate the Withdrawal:
• Use the transfer function on the Card smart contract. This function allows you to specify the token type, recipient address, and amount to withdraw, enabling a direct transfer from the card wallet to the chosen address. - Execute Transfer:
• Set up the necessary parameters for the transfer function call, including the token address, recipient address, and amount to transfer. Execute the call through the ABI, which processes the withdrawal from the card wallet. - Verify Withdrawal:
• After submitting the transaction, confirm that the funds have been successfully transferred from the card wallet. Checking the transaction receipt helps ensure that the balance in the card wallet has been updated accordingly.
Example at Python
from web3 import Web3
# Replace with your RPC server URL
rpc_url = "https://wirex-devnet-rpc.eu-north-2.gateway.fm/"
# Load Card Transfer ABI
contract_abi = [
{
"inputs": [
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
# Add the rest of the ABI if necessary
]
# Replace with your contract address
contract_address = "{cardWalletAddress}"
# Replace with your private key for signing the transaction
private_key = "{privateKey}"
# Replace with your Ethereum wallet address
account_address = "0x848efaC21cdBA93b481F1a40b54Af00A8Db994c0"
# Connect to the Ethereum network via the provided RPC URL
web3 = Web3(Web3.HTTPProvider(rpc_url))
if web3.is_connected():
print("Connected to the Wirex Pay Testnet network")
else:
print("Failed to connect")
# Create the contract instance
contract = web3.eth.contract(address=contract_address, abi=contract_abi)
# Set parameters for withdrawal
token_address = "{tokenAddress}" # Token address (e.g., stablecoin contract)
recipient_address = "{eecipientWalletAddress}"
amount = web3.to_wei(1, 'ether') # specify amount to transfer
# Get the nonce (transaction count) for the account
nonce = web3.eth.get_transaction_count(account_address)
# Build the transaction to call the `createAccount` function
txn = contract.functions.transfer(token_address, recipient_address, amount).build_transaction({
'chainId': 230378335, # Use appropriate chain ID, 1 for mainnet
'gas': 200000, # Estimate gas
'gasPrice': 0, # Set appropriate gas price
'nonce': nonce
})
# Sign the transaction using the private key
signed_txn = web3.eth.account.sign_transaction(txn, private_key=private_key)
# Send the signed transaction
tx_hash = web3.eth.send_raw_transaction(signed_txn.raw_transaction)
# Print the transaction hash
print(f"Transaction hash: {tx_hash.hex()}")
# Wait for the transaction receipt (optional)
receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Transaction receipt: {receipt}")
Updated 4 months ago