Using a Monero wallet through a Telegram bot

Because I don't know any Monero wallets on a mobile device, and in Trust Wallet And Cryptobot I simply don’t have this coin, I decided to make my own implementation, which surprisingly can be considered MVP and freely accept and translate XMR.

First, let's download Monero CLI Walletin order to interact with the blockchain:

https://www.getmonero.org/downloads/

We unpack the archive, first of all we launch the wallet itself via:

./monero-wallet-cli

Create a wallet file name and password. The wallet is ready.

Next, download the blockchain, the whole or pruned version (200-100GB).

Can be installed as a service via systemdor to the background via nohup.

Blockchain download example entirely: (>150GB)

nohup ./monerod --rpc-bind-ip 0.0.0.0 --rpc-bind-port 18081 --confirm-external-bind &

Pruned version: (<100GB)

nohup ./monerod --rpc-bind-ip 0.0.0.0 --rpc-bind-port 18081 --confirm-external-bind --prune-blocks &

Bindite RPC on 0.0.0.0 so that your node is accessible from the Internet to other users.

Bindite RPC on 127.0.0.1 for access only from the local network for the bot. (put away –confirm-external-bind)

The local node is ready.

Next, let's launch ./monero-wallet-rpc for wallet transactions.

nohup ./monero-wallet-rpc --rpc-bind-ip 127.0.0.1 --rpc-bind-port 18083 --wallet-file {path_to_wallet_file} --password "habrahabr" --daemon-host 127.0.0.1:18081 --trusted-daemon --disable-rpc-login &

Done, now you can use the methods from RPC documentation: https://www.getmonero.org/resources/developer-guides/wallet-rpc.html

Including: creating addresses, transfer of funds And export transactions. Using 127.0.0.1:18083/json_rpc.

For example, let's see the wallet balance using python requests:

url = "http://127.0.0.1:18083/json_rpc"
headers = { 'content-type': 'application/json' }

payload = json.dumps({
“jsonrpc”:”2.0″,
“id”:”0″,
“method”:”get_balance”,
“params”:{
“account_index”:0,
“address_indices”:[0]
}
})
response = requests.post(url, data=payload, headers=headers)

print(response.json())

RPC returns the balance in the form of atomic units to convert it into the usual form XMR:
format(atomic_units / (10**12), ".12f")

And back, for example, to send funds: (Function transferrespectively)
int(float(xmr_amount) * (10**12))

Function implementation: https://t.me/wallet_xmrbot

Source code: https://github.com/amlkyc/xmrbot

aiogram 3

aiogram 3

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *