Automated Bitcoin forwarding to another Bitcoin address

This post is also available in: German

Automated Bitcoin forwarding to another Bitcoin address

This article about Bitcoin forwarding explains how Bitcoin is automatically forwarded to another Bitcoin address.

If you sell something in our shop against Bitcoin, these Bitcoin payments are credited to the internal BTCPay Bitcoin Wallet. From this Bitcoin Wallet, the Bitcoins are to be automatically forwarded to our Bitcoin Wallet at a Bitcoin exchange.

This automated Bitcoin forwarding from the internal BTCPay Bitcoin Wallet to the Bitcoin Wallet to the Bitcoin Exchange is described here.

The procedure

If a customer successfully pays with Bitcoin, these Bitcoins are credited to the internal BTCPay Wallet. The BTCPay system is thus able to monitor the status of the respective payments. After the receipt of payment has been successfully completed, these Bitcoin should be forwarded. If you want to keep the Bitcoin, the Bitcoin can be forwarded to your own wallet.

If you would prefer to receive Euro or another Fiat currency instead of Bitcoin, the Bitcoins can be forwarded to a Bitcoin exchange so that the Bitcoins you receive can be converted into Euro.

Forwarding takes place as soon as there is only one Satoshi on the internal BTCPay wallet. The forwarding should be immediate and automated.

What you require

For the implementation of the described procedure you need:

  • internal BTCPay Bitcoin Wallet
  • BTCPay Transmuter Access

Technical implementation

The forwarding is implemented on the basis of BTCPay Transmuter. We will configure and set up some external services for this. These External Services are combined with trigger and action statements and are combined as one Recipe.

We will create a Recipe for our requirements and thus start with the creation of a new Recipe.

We give our Recipe a unique name and choose for our example: “Send BTC to Exchange” and the description: “Automated forwarding to another Bitcoin address

Create a Recipe at BTCPay Transmuter

The first step is to define the trigger. We receive a variety of triggers, which are provided to us by BTCPay Transmuter.

As soon as there is Bitcoin credit on a particular Bitcoin Wallet, this credit should be forwarded to another Bitcoin address.

Therefore we choose the “Balance Check” variant as trigger.

Overview of trigger possibilities with BTCPay transmuter

This trigger is intended to monitor the credit balance of the Wallet. Now the question arises which Bitcoin Wallet should be monitored. This is recorded in the following step.

An External Service is now required for this, which is created at this point. With the help of NBXplorer you can determine the changes of a specific Bitcoin Wallet. Since we have not yet created a monitoring service based on NBXplorer as an External Service, we now create an

Create a balance trigger for BTCPay transmuter

We give this wallet a unique name and choose as type: “NBXplorerWallet External Services”.

Erstellung NBXplorer Wallet at BTCPay Transmuter

Then we have to tell the surveillance service which wallet to monitor. This is the internal BTCPay Wallet, which belongs to the Supporter Shop, which is located on our Demo BTCPay Server.

Therefore we have to pair the NBXplorerWallet External Service with the Supporter Shop.

Connect BTCPay Server at Demo.coincharge.io

Click Save, then the page appears again with the link.

Connect BTCPay Server at Demo.coincharge.io

Now we click on the link to authorize the pairing process.

BTC Transmuter pairing with BTCPay Store

Select the appropriate shop and click on Approve.

Then we go back to the BTCPay Transmuter page and there to the menu item Recipes. There our Recipe with the designation: “Send BTC to Exchange” should be listed:

Automatic Bitcoin forwarding

We click on Edit to continue with our setup.

In the following view we are offered the option “Wallet Generator”.

Edit NBXplorer Wallet Generator BTCPay Transmuter

We would use the Wallet Generator option if we wanted to create a new wallet. We do not need a new wallet because we want to use the internal BTCPay wallet which is linked to our Supporter Shop.

It should be mentioned at this point that one could create one’s own wallet at this point and that the relevant information would be made available in this form.

Generate BTC Wallet at BTCPay Transmutter

As already mentioned, we want to use the already existing BTCPay Wallet and need the corresponding information.

These can be found on the BTCPay server in the menu item Wallets. There we select the corresponding BTCPay store and find the wallet settings:

manage BTCpay Wallet

In the Settings section, we find the so-called Public Key (xpub) in the Derivation Scheme field.

It is important that this XPub key is extended by the information about the Address Type. This was defined when the shop was created. At that time we decided to use the address type P2SH-P2WPKH and now we have to addto [p2sh] our XPUB key.

We copy this information to the Derivation Strategy field

Edit NBXplorer Wallet BTCPay Transmuter

The Private Key is required so that something can be paid out from this wallet. This private key can be a mnemonic seed (12 or 24 words), a passphrase or a private key. One variant is required. Therefore not all fields have to be filled in. One of the three fields is sufficient.

Watch out!

Whoever has the Private Key also has the Bitcoin. Therefore handle the private key very conscientiously. Be aware of what you are doing. Never store this private key on the Coincharge demo server. Only to try it out. Use your own BTCPay server and never leave a large amount of Bitcoin that you cannot afford to lose.

In our case, the Bitcoin remains on this wallet for at most a millisecond. Nevertheless, one should be aware of the risk.

We click on Save and get the following view.

Edit External Service BTCPay Transmuter

Now we still have to define the trigger and the action.

We go to our Recipe at Recipes and there to Edit.

On the following page we edit the trigger and click on Add.

Add trigger BTCPay Transmuter

With the trigger we define the condition under which something should happen. We want something to happen when the balance on our wallet changes.

Balance trigger BTCPay Transmuter

We define for our case that if the balance is greater than zero, then something should happen.

After we have saved the trigger, we have to define the action.

Edit Recipe Trigger BTCPay Transmuter

For this we click on Add Action Group and get a selection of predefined options.

Overview of action possibilities with BTCPay transmuter

As soon as a credit balance is received on our Wallet, it shall be forwarded immediately. We select the action “Send Transaction” accordingly.

On the following page we click on Add.

Send Transaction Action Transaction Outputs

Then we have the possibility to determine what to do with the credit on the Wallet.

In the Amount field we enter {{TriggerData.Balance.ToDecimal(MoneyUnit.BTC)*(100/100)}}code>

This command says that 100% of the credit should be used. For example, if we would say that we only want to send 50% to the stock exchange and 50% to our own wallet, we could define this accordingly with {{TriggerData.Balance.ToDecimal(MoneyUnit.BTC)*(50/100)}}code>

As destination address we store a static Bitcoin address, which we got from the Bitcoin exchange.

We use a fixed address because the ability to generate a new destination address for each transaction is not available.

BTCPay Transmuter Send Transaction Action

We click on Save and we are done. Now we just need to do the appropriate live testing.

We make a test order in our Supporter Shop. Then we check the logs for the transaction via reipes.

Logfile for successful Bitcoin forwarding to Binance

The forwarding was successful and the Bitcoin exchange also informed us by email about the successful receipt of Bitcoin.

Binance confirmation for Bitcoin inpayment

In this article we have shown how the Bitcoin received in our Shop Wallet can be automatically forwarded to a Bitcoin exchange. Bitcoin can then be sold automatically on the Bitcoin exchange. In the article “Accept Bitcoin and receive Euro” we showed how Bitcoin can be sold automatically on the Bitcoin exchange. This ensures that a merchant can accept Bitcoin and does not have to fear any exchange rate risks against the euro or dollar. The shop sells everything in Euro, the customer pays with Bitcoin and the merchant gets Euro on his bank account.

With the help of BTCPay Transmuter, such automated processes can be implemented for individual requirements on the basis of trigger and action commands.

This post is also available in: German

Leave a reply