-
-
Save AnthonyAkentiev/e8cd38328769284c110626b9e4a1379b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wallet = require('./lib/wallet.js'); | |
const transaction = require('./lib/transaction'); | |
const Tst = require('./build/contracts/Tst.json'); | |
const Tx = require('ethereumjs-tx'); | |
const Web3 = require('web3'); | |
const web3 = new Web3(new Web3.providers.HttpProvider("XXX")); | |
////////////////////// 2 - sell | |
const addressFrom = '0x67c8f059ff3a771dce4b2077eaed5dd18b1ea692'; | |
// to contract | |
const address = '0x65d0200de3803b9d95d87c52bc202bd2da23e481'; | |
const tst = new web3.eth.Contract(Tst.abi, address); | |
// this method has 'revert with string' | |
// i've tried method that doesn't rejects -> everything mined correctly | |
let txInput = tst.methods.sell().encodeABI(); | |
console.log('TX INPUT: ' + txInput); | |
const nonce = 12795; | |
const price = '20000000000'; | |
const limit = '4806770'; | |
async function send(){ | |
// PK is hiden because of security reasons... | |
var privateKey = Buffer.from('XXXXXX', 'hex'); | |
var rawTx = { | |
nonce: nonce, | |
gasPrice: '0x09184e72a000', | |
gasLimit: '0x12710', | |
to: address, | |
data: txInput | |
} | |
var tx = new Tx(rawTx); | |
tx.sign(privateKey); | |
var serializedTx = tx.serialize(); | |
console.log('Sending signed transaction...'); | |
try { | |
web3.eth.handleRevert = true; | |
await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')); | |
} catch(err){ | |
console.log('ON error: ', err); | |
console.log('REASON: ' + err.reason); | |
} | |
/* | |
// ALSO tried this way with same result: | |
var x = web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')); | |
x.on("transactionHash", (hash) => { | |
console.log('ON transactionHash: ' + hash); | |
}).on('receipt',(receipt) => { | |
console.log('ON receipt: ', receipt); | |
}).on('error', (err) => { | |
console.log('ON error: ', err); | |
console.log('REASON: ' + err.reason); | |
}); | |
await x; | |
*/ | |
} | |
send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment