A contract SimpleStorage.sol
has been compiled by Truffle using truffle compile
. Its artifact is found at build/contracts/SimpleStorage.json
.
However, this contract should only be deployed to the Ethereum network when a user clicks a button.
When handling the button click, what should be done to deploy the artifact once I get the TruffleContract
object?
Can we also get the transaction hash and contract address after it is deployed?
import SimpleStorageContract from '../../../build/contracts/SimpleStorage.json';
onDeployButtonClick() {
const contract = require('truffle-contract');
const simpleStorage = contract(SimpleStorageContract);
simpleStorage.setProvider(this.props.web3.currentProvider);
// How to deploy this contract to the Ethereum network?
// then get the TX hash and contract address
}
Tried this code on testrpc
onDeployButtonClick() {
const contract = require('truffle-contract');
const simpleStorage = contract(SimpleStorageContract);
simpleStorage.setProvider(this.props.web3.currentProvider);
this.props.web3.eth.getAccounts((error, accounts) => {
simpleStorage.new([], {from: accounts[0]})
})
}
but in the JS console, when onDeployButtonClick
is triggered, I get an error
Uncaught (in promise) Error: VM Exception while processing transaction: out of gas
at Object.InvalidResponse (errors.js:35)
at requestmanager.js:86
at XMLHttpRequest.r
simpleStorage.new().then(instance => {...})
See docs on the new methodtestrpc
. Updated original post200000
. Is there a way to estimate how much gas is need? Is there an auto option for setting gas?