Tengo clave privada de cuenta, dirección de contrato y abi y necesito llamar a la función de contrato con esta cuenta. ¿Es posible?
Junto con web3, debe usar ethereumjs-tx para firmar la transacción y puede enviar web3.eth.sendRawTransaction a la red. A continuación el código para su referencia.
const Web3 = require("web3");
const solc = require("solc");
const Tx = require('ethereumjs-tx')
const web3 = new Web3(new
Web3.providers.HttpProvider("https://ropsten.infura.io"));
var account = "Your Account #";
var key = new Buffer('Your Account # Private key', 'hex')
var abi = ABI of the Contract
var bytecode = Bytecode of compiled contract
var Contract = web3.eth.contract(abi)
const gasPrice = web3.eth.gasPrice;
const gasPriceHex = web3.toHex(gasPrice);
const gasLimitHex = web3.toHex(3000000);
var tra = {
gasPrice: gasPriceHex,
gasLimit: gasLimitHex,
data: bytecode,
from: account
};
var tx = new Tx(tra);
tx.sign(key);
var stx = tx.serialize();
web3.eth.sendRawTransaction('0x' + stx.toString('hex'), (err, hash) => {
if (err) { console.log(err); return; }
console.log('contract creation tx: ' + hash);
});
chico qwerty
Klesun
Daniel Kmak