<script>
const contractAddress = '0xYourContractAddress'; // استبدل بعنوان عقدك الذكي
const contractABI = [ /* ABI الخاصة بعقد BMS */ ];
let web3;
let userAccount;
let bmsContract;
// الاتصال بـ MetaMask
async function connectMetaMask() {
if (typeof window.ethereum !== 'undefined') {
web3 = new Web3(window.ethereum);
await window.ethereum.request({ method: 'eth_requestAccounts' });
const accounts = await web3.eth.getAccounts();
userAccount = accounts[0];
bmsContract = new web3.eth.Contract(contractABI, contractAddress);
document.getElementById('walletAddress').innerText = عنوان المحفظة: ${userAccount};
checkBalance();
} else {
alert("يرجى تثبيت MetaMask أولاً!");
}
}
// شراء عملة BMS
async function buyTokens() {
const amountInEth = document.getElementById('amount').value;
if (amountInEth > 0) {
const amountInWei = web3.utils.toWei(amountInEth, 'ether');
try {
await bmsContract.methods.buyTokens().send({ from: userAccount, value: amountInWei });
alert('تم شراء عملة BMS بنجاح');
} catch (error) {
console.error("خطأ في المعاملة:", error);
alert("حدث خطأ أثناء شراء العملة");
}
} else {
alert('الرجاء إدخال مبلغ صالح');
}
}
// التحقق من رصيد المستخدم
async function checkBalance() {
const balance = await web3.eth.getBalance(userAccount);
const balanceInEth = web3.utils.fromWei(balance, 'ether');
document.getElementById('balance').innerText = رصيدك من ETH: ${balanceInEth} ETH;
}
</script>
-
Notifications
You must be signed in to change notification settings - Fork 0
NADA304/BMS
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published