contract_file = 'contract.sol'
contract_name = ':SimpleContract'
Solc = require('solc')
Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
source_code = fs.readFileSync(contract_file).toString()
admin_account = web3.eth.accounts[0]
compiledContract = Solc.compile(source_code)
abi = compiledContract.contracts[contract_name].interface
bytecode = compiledContract.contracts[contract_name].bytecode;
ContractClass = web3.eth.contract(JSON.parse(abi))
contract_init_data = {
data: bytecode,
from: admin_account,
gas: 1000000,
}
deployed_contract = ContractClass.new(contract_init_data)
contract_instance = ContractClass.at(deployed_contract.address)
until here, this works. But the line msg.sender.transfer(amount); in my contract wouldn't compile on web3.
I then try to add ether to the contract like this:
load_up = {
from: admin_account,
to: deployed_contract.address,
value: web3.toWei(1, 'ether'),
}
web3.eth.sendTransaction(load_up)
and I get:
Error: VM Exception while processing transaction: invalid opcode