Nim Donation button with fixed dollar amount

I was surprised to discover there is no way to create a Nimiq donation button where the donator can donate only a specific dollar amount, and that amount only.
Lets say “Donate 1$” button, where there is a real time price check so the donator doesn’t have to check externally how many Nim are required to build 1$.
The button has to be reused multiple times, so no, is not a viable solution.
Any idea how ?

This can be done by adding a snippet of Javascript code to the page/button to request the current rate from a free API like the one used on the official wallet.

Although if multi-currency support were added to payments links on the wallet it would be much easier, for instance with a URL like this for the donation button:

Where you want to place a donation button use "#" as the href link and donate(1, 'usd') as the onClick event handler like this:

<a href="#" onClick="donate(1, 'usd')"><img src="button.svg" /></a>

Before the </body> tag in the HTML document in the page where you added the button put this snippet:

  function donate(a, c) {
    fetch('' + c)
    .then(r => r.json())
    .then(d =>''+(a/d['nimiq-2'][c]).toFixed(5), '_blank'));

Replace NQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your donation address and adjust donate(1, 'usd') with the amount and currency you want.

Check this for a list with all supported currencies.

1 Like

If I change the button code like that, who presses the button is projected to pay 1 Nim, not 1 usd equivalent. I am guessing there is something else that should be done. I am not a programmer.

I don’t know the HTML /java script at all.
Would you be so kind to say exactly how can I make that button appear correctly ?

When you say “body” I don’t know how to build the whole thing together. I am just a copy and paste guy. Level 0 basically.

I am using a simple free wordpress blog.

@ekamask20 I’m pretty sure there are some plugins that would allow you to add the snippet and the customized button to your Wordpress installation so that you’d only have to copy/paste the code with minimum modifications. Another option would be that this functionality were added to the Nimiq Wordpress plugin to allow support for multiple currencies and automatic conversion to NIM for donation buttons without the need to have WooCommerce installed.

I created an issue for this feature at the official repository on GitHub.