Created
December 23, 2021 12:51
-
-
Save TheBojda/a001fedc87f9978e4ef79b684f5e1194 to your computer and use it in GitHub Desktop.
Ethereum crowdfunding widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const web3 = new Web3(config.PROVIDER_URL) | |
const balance = parseInt(await web3.eth.getBalance(config.ETH_ADDRESS)) | |
const canvas = createCanvas(200, 270) | |
const ctx = canvas.getContext('2d') | |
ctx.fillStyle = "#aaaaaa" | |
ctx.fillRect(0, 0, canvas.width, canvas.height) | |
let qrcode = new Image() | |
qrcode.src = await QRCode.toDataURL(config.ETH_ADDRESS) | |
ctx.drawImage(qrcode, 10, 10, 180, 180) | |
ctx.fillStyle = '#000000' | |
ctx.font = '12px Impact' | |
ctx.fillText(config.TEXT, 10, 210) | |
ctx.fillText(`${(balance / 10 ** 18).toFixed(2).toString()} ${config.SYMBOL} / ${config.TARGET_VALUE.toFixed(2).toString()} ${config.SYMBOL}`, 10, 230) | |
ctx.fillStyle = '#ffffff' | |
ctx.fillRect(10, 240, 180, 10) | |
let percent = balance / (config.TARGET_VALUE * 10 ** 18); | |
if (percent > 1) | |
percent = 1; | |
ctx.fillStyle = '#037362' | |
ctx.fillRect(10, 240, Math.round(180 * percent), 10) | |
ctx.strokeStyle = '#000000' | |
ctx.lineWidth = 1 | |
ctx.strokeRect(10, 240, 180, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can find the full repo here: https://github.com/TheBojda/Ethereum-crowdfunding-widget-javascript