Expert Q&A
Ask Polygon community experts
Posts
42- Expert Q&AMar 29, 2025
How to generate random number out of 1 & 2 not with VRF, and code review help
So I was making a coinflip game which assigns head- 1 and tails -2 and when user places bet on polygon chain.... smart contract generates a random number between 1 and 2 and if the outcome is same...user gets double - (5 % as fee to the owner of contract) ! from a pool and if outcome is different then user loses all and the lost amount is deposited in the pool - (3% as fee to the owner) (to fund winners)... but any way to make genrate a random number? I have no funds at all so I can't afford chainlink VRF to generate. So is there any other secure way for this? plus I am pritty new to solidity so I made this code with help of chat gpt but I don't it works....can anyone help to make the code better? code- // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract CoinFlip { address public owner; uint256 public contractBalance; event BetPlaced(address indexed player, uint256 amount, bool choice); event BetResult(address indexed player, uint256 amount, bool won); constructor() { owner = msg.sender; } function placeBet(bool choice) external payable { require(msg.value > 0, "Bet amount must be greater than 0"); bool outcome = (block.timestamp % 2 == 0); // Simple pseudo-random outcome if (outcome == choice) { uint256 winAmount = (msg.value * 2 * 95) / 100; require(address(this).balance >= winAmount, "Insufficient contract balance"); payable(msg.sender).transfer(winAmount); emit BetResult(msg.sender, winAmount, true); } else { uint256 lostAmount = (msg.value * 97) / 100; contractBalance += lostAmount; emit BetResult(msg.sender, msg.value, false); } emit BetPlaced(msg.sender, msg.value, choice); } function depositFunds() external payable { require(msg.sender == owner, "Only owner can deposit funds"); contractBalance += msg.value; } function withdrawFunds(uint256 amount) external { require(msg.sender == owner, "Only owner can withdraw funds"); require(amount <= address(this).balance, "Insufficient contract balance"); payable(owner).transfer(amount); contractBalance -= amount; } } `
- Polygon PoS
- General
- Smart Contract
- dApp
00 - Expert Q&AMar 27, 2025
How to fix 'Head state missing' error in Bor node?
Hey folks, I just ran into an issue with my Bor node today. It's not syncing currently and I'm seeing the error: 'WARN [03-13|16:26:04.518] Head state missing, repairing'. I was previously synced up until today. I'm running a mainnet node, and I need to figure out how to fix this. Can someone please help?
- Polygon Edge
22Best Answer - Expert Q&AMar 26, 2025
How to maintain a fast and reliable Polygon node sync?
I'm trying to maintain my Polygon node to work all the time and ensure fast sync speeds. I have set the maximum peers to 150, but I'm only getting around 120 after a week. I restart my node occasionally and want it to be as close to validators as possible. I already have a few nodes but need more trusted nodes for better sync performance. Could anyone share some good enodes or advice for improving sync speed?
- Polygon PoS
12Best Answer - Expert Q&AMar 22, 2025
How to add your token to Polygon Portal bridge?
Hi everyone! I've deployed my token on the Polygon POS network, but I'm looking to bridge it through the Polygon Portal bridge. I was wondering how I can add my token to the bridge? Initially, I thought all bridges would just handle deployment for me, but from what I understand, the bridging might only work with tokens originally deployed on Ethereum. Any tips on how this process works would be much appreciated!
- Polygon zkEVM
22Best Answer - Expert Q&ALently142Mar 21, 2025
Need example config.toml for vaultstaking issues
Hey everyone, I'm trying to get a snapshot with vaultstaking and I'm getting the error 'WARN: Synchronisation failed due to whitelist validation'. I suspect it might be something config-related with peers. Can someone share their config.toml file to help me troubleshoot this issue?
- General
21 - Expert Q&AGojo104Mar 20, 2025
How to bridge Sepolia ERC20 tokens to Amoy network?
Hey! I need to bridge ERC20 tokens from the Sepolia network to the Amoy network. I'm looking for documentation or steps to accomplish this process. Can someone guide me?
- Polygon zkEVM
22 - Expert Q&ACattos80Mar 19, 2025
How to resolve Heimdall seed connection errors?
I'm having trouble with my Heimdall node not being able to connect to any seeds. I've followed the docs and started the Bor service, but I get errors like 'Couldn’t connect to any seeds' and it seems the Heimdall rest server shuts down. What steps can I take to resolve this issue and ensure my node connects properly?
- General
21 - Expert Q&AMar 16, 2025
How to download and extract .tar.zst files without saving?
Hey folks, I'm trying to figure out if there's a way to download a snapshot image as a .tar.zst file and unzip (extract) it while it's downloading. The aim is to avoid saving the .tar.zst file to my hard disk entirely. Any tips on how to achieve this?
- Polygon PoS
01Best Answer - Expert Q&AGojo104Mar 14, 2025
How to get current timestamp in smart contracts on Amoy Testnet?
Hey tech community! So, I'm super new to all of this and currently running some tests on the Amoy testnet. I need to access current timestamp data in my smart contract. I've heard of Chainlink feeds or Time Oracles, but I'm not sure if they're available on Amoy or what alternatives I can use. Any tips or contract addresses I can try to integrate into my smart contract for fetching the current time? Appreciate any input or guidance on this!
- Smart Contract
12 - Expert Q&AITachi92Mar 13, 2025
Getting the latest nonce with web3.js
Hey folks! I've been using web3.eth.getTransactionCount with 'pending' to get the nonce, but it doesn't seem to return the latest one. Is there any way to get an accurate nonce, or should I consider using another service?
- Polygon Edge
22Best Answer
- 160
- 149
- 142
- 106
- 104
- 92
- 90
- 87
- 83
- 83
- Polygon PoS
- MATIC
- General
- Polygon zkEVM
- Smart Contract
- Polygon Edge
- Wallet
- dApp
- Polygon Avail
- Polygon Miden