'How can I send arguments for constructor with ethereumjs-tx?
const Web3 = require('web3');
var Tx = require('ethereumjs-tx').Transaction;
const web3 = new Web3('https://rinkeby.infura.io/v3/562f92f28a13469cac6f5d000000');
var myAddress = '0xmyaddress';
const privateKey = Buffer.from('d13c6myprivatekey...', 'hex');
var data = '608060405234801561001057600080fd5b50604051610856380380610856833981810160405281019061003291906100ba565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600281905550506100e7565b600080fd5b6000819050919050565b61009781610084565b81146100a257600080fd5b50565b6000815190506100b48161008e565b92915050565b6000602082840312156100d0576100cf61007f565b5b60006100de848285016100a5565b91505092915050565b610760806100f66000396000f3fe6080604052600436106100705760003560e01c80637ebd1b301161004e5780637ebd1b30146101085780638da5cb5b14610145578063a9518e8814610170578063f274c8971461017a57610070565b806312065fe01461007557806318c63f24146100a0578063471f7cdf146100dd575b600080fd5b34801561008157600080fd5b5061008a6101a3565b6040516100979190610425565b60405180910390f35b3480156100ac57600080fd5b506100c760048036038101906100c291906104a3565b6101be565b6040516100d491906104eb565b60405180910390f35b3480156100e957600080fd5b506100f2610271565b6040516100ff9190610425565b60405180910390f35b34801561011457600080fd5b5061012f600480360381019061012a9190610532565b610277565b60405161013c919061056e565b60405180910390f35b34801561015157600080fd5b5061015a6102b6565b604051610167919061056e565b60405180910390f35b6101786102da565b005b34801561018657600080fd5b506101a1600480360381019061019c9190610589565b610353565b005b6000670de0b6b3a7640000476101b99190610627565b905090565b6000806000905060005b60018054905081101561026757600181815481106101e9576101e8610658565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614156102505760019150610267565b60009150808061025f90610687565b9150506101c8565b5080915050919050565b60025481565b6001818154811061028757600080fd5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b670de0b6b3a764000034146102ee57600080fd5b6001339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103ab57600080fd5b670de0b6b3a7640000816103bf91906106d0565b90508173ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015610407573d6000803e3d6000fd5b505050565b6000819050919050565b61041f8161040c565b82525050565b600060208201905061043a6000830184610416565b92915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061047082610445565b9050919050565b61048081610465565b811461048b57600080fd5b50565b60008135905061049d81610477565b92915050565b6000602082840312156104b9576104b8610440565b5b60006104c78482850161048e565b91505092915050565b60008115159050919050565b6104e5816104d0565b82525050565b600060208201905061050060008301846104dc565b92915050565b61050f8161040c565b811461051a57600080fd5b50565b60008135905061052c81610506565b92915050565b60006020828403121561054857610547610440565b5b60006105568482850161051d565b91505092915050565b61056881610465565b82525050565b6000602082019050610583600083018461055f565b92915050565b600080604083850312156105a05761059f610440565b5b60006105ae8582860161048e565b92505060206105bf8582860161051d565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006106328261040c565b915061063d8361040c565b92508261064d5761064c6105c9565b5b828204905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006106928261040c565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156106c5576106c46105f8565b5b600182019050919050565b60006106db8261040c565b91506106e68361040c565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561071f5761071e6105f8565b5b82820290509291505056fea26469706673582212202d1b2039f994e7ff1b7f1b4afa5516b983d65d7a2427511372101c43d5babc5e64736f6c634300080'
web3.eth.getTransactionCount(myAddress, (err, TxCount) => {
const txObject = {
nonce: web3.utils.toHex(TxCount),
gasLimit: web3.utils.toHex(1000000),
gasPrice: web3.utils.toHex(web3.utils.toWei('20', 'gwei')),
data: '0x' + data,
// i tried this but not worked arguments: [web3.utils.toHex(2)]
};
const tx = new Tx(txObject, { chain: 'rinkeby' });
tx.sign(privateKey);
const serializedTx = tx.serialize();
const raw = '0x' + serializedTx.toString('hex');
web3.eth.sendSignedTransaction(raw, (err, TxHash) => {
console.log('error: ', err, 'transaction hash: ', TxHash);
})
})
I tried to add this line arguments: [web3.utils.toHex(2)] for sending arguments and the non-Hex style of this but it shows me "execution reverted" error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
