I want to send ethereum, but by writing code directly, not from the wallet or interface, like "sendrawtransaction" in bitcoin. How can I do that I need the codes or algorithm
1 Answer
There are a number of ways to use the command line to send an ETH transaction. Some of them will depend on whether you are running your own node (like using Geth's console). We'll try to detail a few here.
Seth
For a first recommendation, we'd like to point to Seth by DappTools. If you're used to a Linux-y way of doing things, you'll probably find this tool very intuitive, and it has great docs. The only possible downsides are key management (it relies on other services for key generation, which can have a learning curve if you haven't dug into it yet), and that you'll need the nix package manager if you don't already have it.
Once you have an address set up, using seth is as simple as setting that address as the ETH_FROM
in the .sethrc
, and using a syntax like this (taken from their docs):
$ seth send --value 1 0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359
(that would send 1 wei to the Ethereum Foundation after prompting you for your password)
Geth
If you are running a Geth node, you can send directly using your node. Geth uses a tool called Clef to handle account creation, here's a link to the official docs about how to setup an account:
$ clef init
$ clef newaccount
once you have a Geth node synced, in a terminal (not the one with the node's output, if there is one, it'll need to be a fresh terminal), use:
$ geth attach
to activate the Geth console. Taken from the Geth docs linked above, this would be the syntax for sending 1 ETH from one address to another from inside the console:
eth.sendTransaction({from:"<ADDRESS_0>",to:"<ADDRESS_1>", value: web3.toWei(0.01,"ether")})
Writing a Script
Using a variety of tools you can write a script or use a REPL to generate a transaction. Rather than go through each, we'll leave some links:
JavaScript
- Ethers.js: link to Transaction Methods
- Web3.js: link to
web3.eth.sendTransaction
(used in the Geth console, and mentioned by Ismael in the comments)
Python
- Web3.py: link to Making Transactions
These will most likely need you to set up a provider (a connection to the blockchain), and will involve either importing an account (and maybe unlocking it) or generating one internally.
Good luck!
web3.eth.sendTransaction
.