Created
August 27, 2018 15:50
-
-
Save hjnp/c4f534b0d878ee1bfdd01ad0933d3d61 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
it("testing data payload", async () => { | |
const address = inbox.options.address; | |
const abi = interface; | |
// ganache account 0 | |
const account = "0x962E563Fed877b31fd5108bC27E330354fE8D3a4"; | |
const privateKey = Buffer.from( | |
"3e7966932fba69ea323e8c9223ebecbc2ff06c6d46216577e3c853372d56b5e3", | |
"hex" | |
); | |
const nonce = await web3.eth.getTransactionCount(account); | |
console.log("nonce", nonce); | |
// const data = web3.eth.contract(abi).at(address).inbox.message(); | |
// let inb = await new web3.eth.Contract(JSON.parse(interface), address ); | |
// const data = await inbox.methods.message(); | |
// const dataSigned = data._method.signature; | |
const messageCall = JSON.parse(abi)[1]; | |
console.log("messageCall", messageCall); | |
var signature = `${messageCall.name}(${messageCall.inputs.map(input => messageCall.type).join(",")})`; | |
console.log("\n\n signature ||| ", signature); | |
let signatureHash = web3.utils.sha3(signature); | |
console.log("\n\n signatureHash ", signatureHash); | |
signatureHash = substr_utf8_bytes(signatureHash, 0, 10); | |
console.log("\n\n signature substr_utf8_bytes ||| ", signatureHash); | |
// var signature = item.name + "(" + item.inputs.map(function(input) {return input.type;}).join(",") + ")"; | |
// var hash = web3.sha3(signature); | |
// console.log('\n\n signature', item, '\n \n', signature, hash); | |
let dataEncoded = signatureHash;// this can be with below function with web3 | |
dataEncoded = web3.eth.abi.encodeFunctionCall(messageCall); | |
console.log('\n\n dataEncoded', dataEncoded); | |
const txParams = { | |
from: accounts[0], | |
to: address, | |
nonce: nonce, | |
gasPrice: web3.utils.toHex(web3.utils.toWei("10", "gwei")), | |
gasLimit: 100000, | |
value: "0x00", | |
data: dataEncoded | |
//EIP 155 chainId - mainnet: 1, ropsten: 3 | |
// chainId: 3 | |
}; | |
const tx = new Tx(txParams); | |
tx.sign(privateKey); | |
let serializedTx = tx.serialize(); | |
console.log('serializedTx', serializedTx); | |
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')) | |
.on('receipt 3333', console.log); | |
// let sendRes = await web3SendTransaction({ | |
// nonce: nonce, | |
// from: accounts[0], | |
// to: address, | |
// value: "0x00", | |
// gasPrice: web3.utils.toHex(web3.utils.toWei("10", "gwei")), | |
// gasLimit: 100000, | |
// data: dataEncoded | |
// }); | |
// console.log('sendRes', sendRes); | |
// let receipt1 = await web3.eth.call({ | |
// from: accounts[0], | |
// to: address, | |
// value: "0x00", | |
// data: dataEncoded | |
// }); | |
// console.log('\n\n receipt1111', receipt1); | |
// const decodeP = web3.eth.abi.decodeParameter('string', receipt1); | |
// console.log('decodeP', decodeP); | |
// let message = await inbox.methods.message().call(); | |
// console.log('message', message); | |
// web3.eth.sendTransaction({ | |
// from: accounts[0], | |
// to: address, | |
// value: "0x00", | |
// data: dataEncoded | |
// }) | |
// .on('transactionHash', function(hash){ | |
// console.log('hash', hash); | |
// }) | |
// .on('receipt', function(receipt){ | |
// console.log('receipt', receipt); | |
// }) | |
// // .on('confirmation', function(confirmationNumber, receipt){ | |
// // console.log('receipt', receipt); | |
// // console.log('confirmationNumber', confirmationNumber); | |
// // }) | |
// .on('error', (err) => { | |
// console.log('err', err); | |
// }); | |
console.log('finish'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment