Contract utility library for Ethereum, to easily sign and send raw transactions
npm install contract-utils --save
const { Transaction } = require('contract-utils');
const contracts = {
'erc20': { // contract name
address: '', // contract address
abi: [], // contract abi
},
};
const Transaction = new Transaction('http://localhost:8545', contracts);
// Example signing and sending transaction to a custom ERC20 contract
const txData = {
contractName: 'erc20', // contract name from 'contracts' object
privateKey: 'privateKey', // private key to sign the transaction
gasLimit: 200000, // optional: (default: 200000)
value: 0, // optional value sent in ether (wei) if function is 'payable' (default: 0)
};
Transaction.send(
txData,
'transfer', // method to be called in the contract
'0x...', // @param1
1000000000000000000, // @param2
// ...other params
)
.then(console.log);