Ich habe einen privaten Kontoschlüssel, eine Vertragsadresse und ein abi und ich muss die Vertragsfunktion mit diesem Konto aufrufen. Ist es möglich?
Zusammen mit web3 müssen Sie ethereumjs-tx verwenden , um die Transaktion zu signieren, und Sie können web3.eth.sendRawTransaction an das Netzwerk senden. Unten Code für Ihre Referenz.
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);
});
qwertyboy
Klesun
Daniel Kamak