1.0.2 • Published 7 years ago
ethereum-offline-sign v1.0.2
Ethereum offline sign
Ethereum transaction offline signature tool
About
Sign offline for the ETH transaction and smart contract call message transaction, return transaction data in HEX format. This allows you full control over your account's private key without having to unlock it at the ethereum node
Demo code
Get Started
npm install ethereum-offline-sign --saveTest
npm testAPIS
transferSign(nonce, to, value) Ordinary transactions are signed offline
Inputs
nonceSender noncetoThe destination address of the message, left undefined for a contract-creation transaction.valueThe value transferred for the transaction in Wei
Return value
Signed transaction data in HEX format
Example:
var EtherSigner = require('ethereum-offline-sign');
var gasPrice = web3.eth.gasPrice,
gasLimit = 4000000;
sender = '0x01BF9878a7099b2203838f3a8E7652Ad7B127A26';
senderPrivateKey = '0x01BF9878a7099b2203838f3a8E7652Ad7B127A26';
destination = '0x6CE18EA1f852367f3fB6b4ad76D58f65374D9920';
nonce = await web3.eth.getTransactionCount(sender);
value = etherSigner.toWei(0.1, 'ether');
//Instantiation EtherSigner
var etherSigner = new EtherSigner(null, senderPrivateKey, gasPrice, gasLimit);
//Sign transactions offline, return signed transaction data in HEX format
var sigTx = etherSigner.transferSign(nonce, destination, value);
web3.eth.sendRawTransaction(sigTx);deployContractSign(contract, arguments, nonce) Sign the deployed contracts
Inputs
contractContains contract instances of the abi, eg:web3.eth.contract(Contract.abi);argumentsContract constructor parameters, Type arraynonceContract creator nonce
Return value
Signed transaction data in HEX format
Example:
var relayContract = require('./contracts/RelayWallet.sol.js');
var contract = web3.eth.contract(relayContract.abi);
var params = [
destination,
{
data: relayContract.bytecode,
gas: gasLimit,
from: sender
}
];
//Sign deploy contract offline, return signed transaction data in HEX format
var sigTx = etherSigner.deployContractSign(contract, params, nonce);
web3.eth.sendRawTransaction(sigTx);contractTransferSign(method, arguments, to, nonce, value) Sign the contract function call
Inputs
methodContract functionargumentsContract function args, Type arraytoContract addressnonceSender account noncevalueETH amount, default 0
Return value
Signed transaction data in HEX format
Example:
var relayContract = require('./contracts/RelayWallet.sol.js');
//relayAddress is delpoyed contract address
let relayWallet = web3.eth.contract(relayContract.abi).at(relayAddress);
let etherSigner = new EtherSigner(relayWallet, senderPrivateKey, gasPrice, gasLimit);
var params = [
{
gasPrice,
gas: gasLimit,
from: sender
}
];
//Sign deploy contract offline, return signed transaction data in HEX format
var sigTx = etherSigner.contractTransferSign('withdrawToDest', params, relayAddress, nonce, 0);
web3.eth.sendRawTransaction(sigTx);getAddress()
Return value
Returns the ethereum address of a current private key
Example:
etherSigner.getAddress()
// 0x01bf9878a7099b2203838f3a8e7652ad7b127a26