【完整版】区块链钱包开发之monero(XMR)门罗币踩坑经验

建议使用python或JavaScript语言开发【这里使用python】

门罗唯一官网【下载钱包同步区块,自己搭建节点】:https://www.getmonero.org/downloads/

使用的库:https://pypi.org/project/monero/

库文档:https://monero-python.readthedocs.io/en/latest/quickstart.html#start-the-rpc-server

官方文档:https://monero-python.readthedocs.io/en/latest/backends.html

参考别人的【区块链钱包开发之monero(XMR)门罗币踩坑经验【python转账的速度很慢的解决办法】:https://blog.csdn.net/qq_38052781/article/details/88658300】:

【第一个坑】如果使用第三方节点【只能同步钱包,但是不能直接在python程序中使用】第三方免费节点大全:https://moneroworld.com/

如何在python中连接钱包,并进行操作:

第一步:在服务器搭建钱包节点,同步完成后,请使用

monero-wallet-cli命令开启一个你的钱包线程【然后通过外部python访问】

案例:

./monero-wallet-rpc --help  # 查看更多的参数配置
[root@VM-16-15-centos monero-x86_64-linux-gnu-v0.17.1.5]# ./monero-wallet-rpc --help
Monero 'Oxygen Orion' (v0.17.1.5-release)

This is the command line monero wallet. It needs to connect to a monero
daemon to work correctly.

Usage:
  monero-wallet-rpc [--wallet-file=<file>|--generate-from-json=<file>|--wallet-dir=<directory>] [--rpc-bind-port=<port>]

General options:
  --help                                Produce help message
  --version                             Output version information

Wallet options:
  --daemon-address arg                  Use daemon instance at <host>:<port>
  --daemon-host arg                     Use daemon instance at host <arg> 
                                        instead of localhost
  --proxy arg                           [<ip>:]<port> socks proxy to use for 
                                        daemon connections
  --trusted-daemon                      Enable commands which rely on a trusted
                                        daemon
  --untrusted-daemon                    Disable commands which rely on a 
                                        trusted daemon
  --password arg                        Wallet password (escape/quote as 
                                        needed)
  --password-file arg                   Wallet password file
  --daemon-port arg (=0)                Use daemon instance at port <arg> 
                                        instead of 18081
  --daemon-login arg                    Specify username[:password] for daemon 
                                        RPC client
  --daemon-ssl arg (=autodetect)        Enable SSL on daemon RPC connections: 
                                        enabled|disabled|autodetect
  --daemon-ssl-private-key arg          Path to a PEM format private key
  --daemon-ssl-certificate arg          Path to a PEM format certificate
  --daemon-ssl-ca-certificates arg      Path to file containing concatenated 
                                        PEM format certificate(s) to replace 
                                        system CA(s).
  --daemon-ssl-allowed-fingerprints arg List of valid fingerprints of allowed 
                                        RPC servers
  --daemon-ssl-allow-any-cert           Allow any SSL certificate from the 
                                        daemon
  --daemon-ssl-allow-chained            Allow user (via --daemon-ssl-ca-certifi
                                        cates) chain certificates
  --testnet                             For testnet. Daemon must also be 
                                        launched with --testnet flag
  --stagenet                            For stagenet. Daemon must also be 
                                        launched with --stagenet flag
  --shared-ringdb-dir arg (=/root/.shared-ringdb, /root/.shared-ringdb/testnet if 'testnet', /root/.shared-ringdb/stagenet if 'stagenet')
                                        Set shared ring database path
  --kdf-rounds arg (=1)                 Number of rounds for the key derivation
                                        function
  --bitmessage-address arg (=http://localhost:8442/)
                                        Use PyBitmessage instance at URL <arg>
  --bitmessage-login arg (=username:password)
                                        Specify <arg> as username:password for 
                                        PyBitmessage API
  --hw-device arg                       HW device to use
  --hw-device-deriv-path arg            HW device wallet derivation path (e.g.,
                                        SLIP-10)
  --tx-notify arg                       Run a program for each new incoming 
                                        transaction, '%s' will be replaced by 
                                        the transaction hash
  --no-dns                              Do not use DNS
  --offline                             Do not connect to a daemon, nor use DNS
  --extra-entropy arg                   File containing extra entropy to 
                                        initialize the PRNG (any data, aim for 
                                        256 bits of entropy to be useful, which
                                        typically means more than 256 bits of 
                                        data)
  --rpc-bind-port arg                   Sets bind port for server
  --disable-rpc-login                   Disable HTTP authentication for RPC 
                                        connections served by this process
  --restricted-rpc                      Restricts to view-only commands
  --rpc-bind-ip arg (=127.0.0.1)        Specify IP to bind RPC server
  --rpc-bind-ipv6-address arg (=::1)    Specify IPv6 address to bind RPC server
  --rpc-use-ipv6                        Allow IPv6 for RPC
  --rpc-ignore-ipv4                     Ignore unsuccessful IPv4 bind for RPC
  --rpc-login arg                       Specify username[:password] required 
                                        for RPC server
  --confirm-external-bind               Confirm rpc-bind-ip value is NOT a 
                                        loopback (local) IP
  --rpc-access-control-origins arg      Specify a comma separated list of 
                                        origins to allow cross origin resource 
                                        sharing
  --rpc-ssl arg (=autodetect)           Enable SSL on RPC connections: 
                                        enabled|disabled|autodetect
  --rpc-ssl-private-key arg             Path to a PEM format private key
  --rpc-ssl-certificate arg             Path to a PEM format certificate
  --rpc-ssl-ca-certificates arg         Path to file containing concatenated 
                                        PEM format certificate(s) to replace 
                                        system CA(s).
  --rpc-ssl-allowed-fingerprints arg    List of certificate fingerprints to 
                                        allow
  --rpc-ssl-allow-chained               Allow user (via --rpc-ssl-certificates)
                                        chain certificates
  --disable-rpc-ban                     Do not ban hosts on RPC errors
  --wallet-file arg                     Use wallet <arg>
  --generate-from-json arg              Generate wallet from JSON format file
  --wallet-dir arg                      Directory for newly created wallets
  --prompt-for-password                 Prompts for password when not provided
  --rpc-client-secret-key arg           Set RPC client secret key for RPC 
                                        payments
  --detach                              Run as daemon
  --pidfile arg                         File path to write the daemon's PID to 
                                        (optional, requires --detach)
  --non-interactive                     Run non-interactive
  --log-file arg                        Specify log file
  --log-level arg                       0-4 or categories
  --max-log-file-size arg (=104850000)  Specify maximum log file size [B]
  --max-log-files arg (=50)             Specify maximum number of rotated log 
                                        files to be saved (no limit by setting 
                                        to 0)
  --max-concurrency arg (=0)            Max number of threads to use for a 
                                        parallel job
  --config-file arg                     Config file

门罗钱包服务器节点运行命令【这里的网络可以为测试网络或主网】【如果增加参数--detach 则代表后台启动】

# 增加--detach代表后台启动【请查看帮助 ./monero-wallet-rpc --help】

./monero-wallet-rpc --testnet --wallet-file testwallet --password walletpassword --confirm-external-bind --rpc-bind-ip 0.0.0.0 --rpc-bind-port 28088 --disable-rpc-login  --detach

然后python写代码:

from monero.wallet import Wallet
from monero.backends.jsonrpc import JSONRPCWallet


wallet = Wallet(JSONRPCWallet(host="服务器外网ip", port=28088)) # 务必确保端口开通

print(wallet.address())

猜你喜欢

转载自blog.csdn.net/weixin_43343144/article/details/110915040