It does not seem that you compiled the source? You just declared a variable holding the source code. That's the main problem.
Also, apparently, your function greet()
is not declared with the keyword constant
. You'll therefore have to call it with greeter.greet.call()
PS : no need to do this complicated stuff to create your development chain. Just run get --dev --mine --minerthreads 1
You are not providing too much informations for me to give you an easy way to do that :) , anyway this is one way to how you can send transaction:
Better to use web3 1.0, you need also install ethereumjs-tx: npm install ethereumjs-tx
const Tx = require('ethereumjs-tx');
to get instance of your contract:
new web3.eth.Contract(jsonInterface, address, options)
Example:
const myContract = new web3.eth.Contract([...], '..address of your contract..', {
defaultAccount: '....', // default from address
defaultGasPrice: '20000000000' // default gas price in wei, 20 gwei in this case
});
and to get the data for the transaction parameter:
const mydata = myContract.methods.greet("<your-greeting.string>").encodeABI()));
to Sign and Send
const privateKey = Buffer('<your privatekey>', 'hex')
const rawTx = {
nonce: <your-tx-nonce.. you can also get it with web3 command >,
gasLimit: web3.toHex(1000000),
gasPrice: web3.toHex(web3.toWei('10', 'gwei')),
to: <your contract address>,
value: '0x00',
data: mydata
}
const tx = new Tx(rawTx);
tx.sign(privateKey);
const serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log);
https://web3js.readthedocs.io/en/1.0/web3-eth.html#sendsignedtransaction
https://web3js.readthedocs.io/en/1.0/web3-eth-abi.html?highlight=encode
Best Answer
In web3py you can use the method buildTransaction:
In your example you can do as follows:
Then you can sign the transaction using:
and finally you can send the transaction signed using:
Hope this helps.