how to sign transaction during contract deployment
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am looking at the web3js documentation to deploy a new contract, however, I see no mention of how to sign the transaction that will deploy the contract in the blockchain...document makes no mention of signing with private key...will appreciate any insight into this
here is the example code snippet from the docs (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract)
myContract.deploy(
data: '0x12345...',
arguments: [123, 'My String']
)
.send(
from: '0x1234567890123456789012345678901234567891',
gas: 1500000,
gasPrice: '30000000000000'
, function(error, transactionHash) ... )
.on('error', function(error) ... )
.on('transactionHash', function(transactionHash) ... )
.on('receipt', function(receipt)
console.log(receipt.contractAddress) // contains the new contract address
)
.on('confirmation', function(confirmationNumber, receipt) ... )
.then(function(newContractInstance)
console.log(newContractInstance.options.address) // instance with the new contract address
);
web3js
add a comment |Â
up vote
1
down vote
favorite
I am looking at the web3js documentation to deploy a new contract, however, I see no mention of how to sign the transaction that will deploy the contract in the blockchain...document makes no mention of signing with private key...will appreciate any insight into this
here is the example code snippet from the docs (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract)
myContract.deploy(
data: '0x12345...',
arguments: [123, 'My String']
)
.send(
from: '0x1234567890123456789012345678901234567891',
gas: 1500000,
gasPrice: '30000000000000'
, function(error, transactionHash) ... )
.on('error', function(error) ... )
.on('transactionHash', function(transactionHash) ... )
.on('receipt', function(receipt)
console.log(receipt.contractAddress) // contains the new contract address
)
.on('confirmation', function(confirmationNumber, receipt) ... )
.then(function(newContractInstance)
console.log(newContractInstance.options.address) // instance with the new contract address
);
web3js
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am looking at the web3js documentation to deploy a new contract, however, I see no mention of how to sign the transaction that will deploy the contract in the blockchain...document makes no mention of signing with private key...will appreciate any insight into this
here is the example code snippet from the docs (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract)
myContract.deploy(
data: '0x12345...',
arguments: [123, 'My String']
)
.send(
from: '0x1234567890123456789012345678901234567891',
gas: 1500000,
gasPrice: '30000000000000'
, function(error, transactionHash) ... )
.on('error', function(error) ... )
.on('transactionHash', function(transactionHash) ... )
.on('receipt', function(receipt)
console.log(receipt.contractAddress) // contains the new contract address
)
.on('confirmation', function(confirmationNumber, receipt) ... )
.then(function(newContractInstance)
console.log(newContractInstance.options.address) // instance with the new contract address
);
web3js
I am looking at the web3js documentation to deploy a new contract, however, I see no mention of how to sign the transaction that will deploy the contract in the blockchain...document makes no mention of signing with private key...will appreciate any insight into this
here is the example code snippet from the docs (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#eth-contract)
myContract.deploy(
data: '0x12345...',
arguments: [123, 'My String']
)
.send(
from: '0x1234567890123456789012345678901234567891',
gas: 1500000,
gasPrice: '30000000000000'
, function(error, transactionHash) ... )
.on('error', function(error) ... )
.on('transactionHash', function(transactionHash) ... )
.on('receipt', function(receipt)
console.log(receipt.contractAddress) // contains the new contract address
)
.on('confirmation', function(confirmationNumber, receipt) ... )
.then(function(newContractInstance)
console.log(newContractInstance.options.address) // instance with the new contract address
);
web3js
asked Sep 3 at 5:55
satyendra
304
304
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
This is the method which can be used to sign transactions.
add a comment |Â
up vote
2
down vote
Try this (using web3.js v1):
let fs = require("fs");
let Web3 = require("web3");
let web3 = new Web3(NODE_ADDRESS);
async function send(transaction)
let gas = await transaction.estimateGas(from: PUBLIC_KEY);
let options =
to : transaction._parent._address,
data: transaction.encodeABI(),
gas : gas
;
let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
async function deploy(contractName, contractArgs)
let abi = fs.readFileSync(contractName + ".abi").toString();
let bin = fs.readFileSync(contractName + ".bin").toString();
let contract = new web3.eth.Contract(JSON.parse(abi));
let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
console.log(`$contractName contract deployed at address $handle.contractAddress`);
return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);
async function run()
let myContract = await deploy("MyContract", [123, "My String"]);
...
add a comment |Â
up vote
2
down vote
Using Web3.js 1.0.0
var contractInstance = new web3.eth.Contract(contractABI);
var deployData = contractInstance.deploy(
data : contractByteCode
).encodeABI();
var tx =
data : deployData
;
web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
);
signTransaction
is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
This is the method which can be used to sign transactions.
add a comment |Â
up vote
3
down vote
This is the method which can be used to sign transactions.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
This is the method which can be used to sign transactions.
This is the method which can be used to sign transactions.
answered Sep 3 at 12:36
Puneet Kumar
47314
47314
add a comment |Â
add a comment |Â
up vote
2
down vote
Try this (using web3.js v1):
let fs = require("fs");
let Web3 = require("web3");
let web3 = new Web3(NODE_ADDRESS);
async function send(transaction)
let gas = await transaction.estimateGas(from: PUBLIC_KEY);
let options =
to : transaction._parent._address,
data: transaction.encodeABI(),
gas : gas
;
let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
async function deploy(contractName, contractArgs)
let abi = fs.readFileSync(contractName + ".abi").toString();
let bin = fs.readFileSync(contractName + ".bin").toString();
let contract = new web3.eth.Contract(JSON.parse(abi));
let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
console.log(`$contractName contract deployed at address $handle.contractAddress`);
return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);
async function run()
let myContract = await deploy("MyContract", [123, "My String"]);
...
add a comment |Â
up vote
2
down vote
Try this (using web3.js v1):
let fs = require("fs");
let Web3 = require("web3");
let web3 = new Web3(NODE_ADDRESS);
async function send(transaction)
let gas = await transaction.estimateGas(from: PUBLIC_KEY);
let options =
to : transaction._parent._address,
data: transaction.encodeABI(),
gas : gas
;
let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
async function deploy(contractName, contractArgs)
let abi = fs.readFileSync(contractName + ".abi").toString();
let bin = fs.readFileSync(contractName + ".bin").toString();
let contract = new web3.eth.Contract(JSON.parse(abi));
let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
console.log(`$contractName contract deployed at address $handle.contractAddress`);
return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);
async function run()
let myContract = await deploy("MyContract", [123, "My String"]);
...
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Try this (using web3.js v1):
let fs = require("fs");
let Web3 = require("web3");
let web3 = new Web3(NODE_ADDRESS);
async function send(transaction)
let gas = await transaction.estimateGas(from: PUBLIC_KEY);
let options =
to : transaction._parent._address,
data: transaction.encodeABI(),
gas : gas
;
let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
async function deploy(contractName, contractArgs)
let abi = fs.readFileSync(contractName + ".abi").toString();
let bin = fs.readFileSync(contractName + ".bin").toString();
let contract = new web3.eth.Contract(JSON.parse(abi));
let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
console.log(`$contractName contract deployed at address $handle.contractAddress`);
return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);
async function run()
let myContract = await deploy("MyContract", [123, "My String"]);
...
Try this (using web3.js v1):
let fs = require("fs");
let Web3 = require("web3");
let web3 = new Web3(NODE_ADDRESS);
async function send(transaction)
let gas = await transaction.estimateGas(from: PUBLIC_KEY);
let options =
to : transaction._parent._address,
data: transaction.encodeABI(),
gas : gas
;
let signedTransaction = await web3.eth.accounts.signTransaction(options, PRIVATE_KEY);
return await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
async function deploy(contractName, contractArgs)
let abi = fs.readFileSync(contractName + ".abi").toString();
let bin = fs.readFileSync(contractName + ".bin").toString();
let contract = new web3.eth.Contract(JSON.parse(abi));
let handle = await send(contract.deploy(data: "0x" + bin, arguments: contractArgs));
console.log(`$contractName contract deployed at address $handle.contractAddress`);
return new web3.eth.Contract(JSON.parse(abi), handle.contractAddress);
async function run()
let myContract = await deploy("MyContract", [123, "My String"]);
...
answered Sep 3 at 7:03
goodvibration
1,754519
1,754519
add a comment |Â
add a comment |Â
up vote
2
down vote
Using Web3.js 1.0.0
var contractInstance = new web3.eth.Contract(contractABI);
var deployData = contractInstance.deploy(
data : contractByteCode
).encodeABI();
var tx =
data : deployData
;
web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
);
signTransaction
is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.
add a comment |Â
up vote
2
down vote
Using Web3.js 1.0.0
var contractInstance = new web3.eth.Contract(contractABI);
var deployData = contractInstance.deploy(
data : contractByteCode
).encodeABI();
var tx =
data : deployData
;
web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
);
signTransaction
is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Using Web3.js 1.0.0
var contractInstance = new web3.eth.Contract(contractABI);
var deployData = contractInstance.deploy(
data : contractByteCode
).encodeABI();
var tx =
data : deployData
;
web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
);
signTransaction
is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.
Using Web3.js 1.0.0
var contractInstance = new web3.eth.Contract(contractABI);
var deployData = contractInstance.deploy(
data : contractByteCode
).encodeABI();
var tx =
data : deployData
;
web3.eth.accounts.signTransaction(tx, privateKey).then (signed =>
web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
);
signTransaction
is the function you need to sign your transaction with the private key. For that you need to construct a transaction with the required data for the contract deployment i.e. contract abi and its byte code. Now, you can sign the trasaction and send it. You will get contract address of the newly deployed contract and other information in transaction receipt.
edited Sep 3 at 7:57
answered Sep 3 at 6:54
biplavo
32117
32117
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f57964%2fhow-to-sign-transaction-during-contract-deployment%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password