Bitcoin Forum
October 06, 2024, 08:17:21 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How i can use electrum in node js ?  (Read 65 times)
hellossy (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 1


View Profile
November 11, 2020, 07:28:23 AM
 #1

Hi. I install electrum on my server. How i can connect to electrum from node js script ? I try build website with bitcoin payment;
I have not found examples of using electrum in the node js
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4361

<insert witty quote here>


View Profile
November 11, 2020, 09:08:42 AM
Merited by ABCbits (1)
 #2

This apparently is a "multicurrency" wallet that uses a local version of electrum to work the "btc" functionality: https://github.com/jesobreira/multiwallet

You can see it just uses the Electrum JSONRPC API to communicate with Electrum from within node.js: https://github.com/jesobreira/multiwallet/blob/master/lib/currencies/btc.js#L122
You can read more about the Electrum JSONRPC here: https://electrum.readthedocs.io/en/latest/jsonrpc.html

Note, I believe that the full list of available commands is the same as you get when you use help() in the Electrum console:
Code:
>>> help()
[
    "add_lightning_request",
    "add_peer",
    "add_request",
    "addtransaction",
    "broadcast",
    "changegaplimit",
    "clear_invoices",
    "clear_ln_blacklist",
    "clear_requests",
    "close_channel",
    "close_wallet",
    "commands",
    "convert_xkey",
    "create",
    "createmultisig",
    "createnewaddress",
    "decode_invoice",
    "decrypt",
    "deserialize",
    "dumpgraph",
    "dumpprivkeys",
    "enable_htlc_settle",
    "encrypt",
    "export_channel_backup",
    "freeze",
    "get",
    "get_channel_ctx",
    "get_ssl_domain",
    "get_tx_status",
    "get_watchtower_ctn",
    "getaddressbalance",
    "getaddresshistory",
    "getaddressunspent",
    "getalias",
    "getbalance",
    "getconfig",
    "getfeerate",
    "getinfo",
    "getmasterprivate",
    "getmerkle",
    "getminacceptablegap",
    "getmpk",
    "getprivatekeyforpath",
    "getprivatekeys",
    "getpubkeys",
    "getrequest",
    "getseed",
    "getservers",
    "gettransaction",
    "getunusedaddress",
    "help",
    "import_channel_backup",
    "importprivkey",
    "init_lightning",
    "inject_fees",
    "is_synchronized",
    "ismine",
    "lightning_history",
    "list_channels",
    "list_invoices",
    "list_peers",
    "list_requests",
    "list_wallets",
    "listaddresses",
    "listcontacts",
    "listunspent",
    "lnpay",
    "load_wallet",
    "make_seed",
    "nodeid",
    "normal_swap",
    "notify",
    "onchain_history",
    "open_channel",
    "password",
    "payto",
    "paytomany",
    "remove_lightning",
    "removelocaltx",
    "restore",
    "reverse_swap",
    "rmrequest",
    "searchcontacts",
    "serialize",
    "setconfig",
    "setlabel",
    "signmessage",
    "signrequest",
    "signtransaction",
    "stop",
    "sweep",
    "unfreeze",
    "validateaddress",
    "verifymessage",
    "version"
]

The documentation for each one isn't great... but reading the python code here should help: https://github.com/spesmilo/electrum/blob/master/electrum/commands.py

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
NotATether
Legendary
*
Offline Offline

Activity: 1750
Merit: 7310


In memory of o_e_l_e_o


View Profile WWW
November 11, 2020, 06:33:37 PM
 #3

If you just need middleware that talks to Electrum from node.js, then the JSONRPC API that HCP posted is sufficient.

If you also need a web frontend, you also need to follow the instructions at https://electrum.readthedocs.io/en/latest/merchant.html, which enables the Electrum daemon to generate a webpage people can pay at.

The most important command you need to run online your terminal is:

Code:
electrum -o setconfig payserver_address ecdsa.org:80

Replace ecdsa.org:80 with your domain name and port. This is the site that Electrum will create the payment frontend on. Then you’d use node.js to programmatically pay it using the appropriate JSONRPC command. But to finish the frontend initialization, you need to also run the other commands in the documentation I linked.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!