Submit a transaction from Autonity NodeJS Console
How to submit transactions to an Autonity network using the NodeJS interface to the RPC API’s
Prerequisites
To submit transactions to a client node from the Autonity NodeJS Console you need:
- An installed NodeJS Console.
- An unlocked account on an Autonity network funded with auton to pay for transaction gas costs.
- Configuration details for the Autonity network you are deploying to, i.e. a public or your own node on a public Autonity network.
Navigate to your Autonity NodeJS Console install directory and initialise a console session, specifying the IP address of the node you will connect to. The connection is made over WebSockets to port 8546:
./console ws://<IP-ADDRESS>:8546
If the transport is over WebSockets or WebSockets Secure will depend on your node setup. For connecting to a public node WebSockets Secure (wss
) is advised.
Examples
Here are some examples of using web3
and autonity
namespaces to transfer value between accounts and call Autonity Protocol Contract ERC20 functionality from the console. In the following examples we will specify the gas parameter, but it can be superfluous depending on how you unlocked your account.
The current block base fee can be obtained by querying the latest block header:
.eth.getBlock(await web3.eth.getBlockNumber())
web3
{baseFeePerGas: 5000,
...
}
For parameter definitions and usage see the Reference Autonity Interfaces.
To see your addresses you can use the command:
.eth.getAccounts() web3
Transfer Auton:
Transferring Autonity’s native account coin using the web3.eth
namespace. Note .send()
is not necessary:
.eth.sendTransaction({to:myAddress, from:myAddress, value:100, gas: gas}) web3
Transfer Newton:
Transferring Autonity’s native stake token using the autonity
namespace. Note use of .send()
:
.transfer('<_recipient>', <_amount>).send({from: myAddress, gas: gas}) autonity
Approve another account to transfer your Newton stake tokens:
.approve('<spender>', <amount>).send({from: myAddress, gas: gas}) autonity
Check approved account’s allowance for transferring Newton stake tokens:
.allowance('<owner>','<spender>').call() autonity
Transfer Newton stake tokens as an approved account:
.transferFrom('<sender>', '<recipient>', <amount>).send({from: myAddress, gas: gas}) autonity