Created
August 13, 2018 15:01
-
-
Save helderjnpinto/0ac87d59d88befce112817d4ddd6e5f9 to your computer and use it in GitHub Desktop.
eth call method on smart contract only with web3
This file contains hidden or 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 contract = new web3.eth.Contract(abiArray, contractAddr); | |
var func = contract.methods.myMethod('foo', 'bar') | |
var encodedFunc = func.encodeABI(); | |
var tx = { | |
from: ownerWallet, | |
to: contractAddr, | |
gas: web3.utils.toHex(1000000), //1m, also tried string '1000000' | |
gasPrice: web3.utils.toHex(20000000000), //20gwei, also tried string '20000000000' | |
data: encodedFunc | |
} | |
//might just be unnecessary three lines | |
const account = web3.eth.accounts.privateKeyToAccount(ownerPrivate) | |
console.log(account) | |
web3.eth.getBalance(ownerWallet).then(console.log) | |
const signed = await web3.eth.accounts.signTransaction(tx, ownerPrivate) | |
var trans = web3.eth.sendSignedTransaction(signed.rawTransaction) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment