I am trying to deploy a smart contract using BrowserSolc and Metamask. and deployed successfully when the contract doesn't have constructor parameters but now I am trying to deploy with the constructor parameter but unable to do it.
How to add a parameter to the send_ethTransaction
method
const source = "pragma solidity 0.4.24;contract SujiToken { string public name = 'Suji'; string public symbol = 'SUJI'; string public standard = 'Suji Token v1.0'; uint256 public totalSupply; event Transfer( address indexed _from, address indexed _to, uint256 _value ); event Approval( address indexed _owner, address indexed _spender, uint256 _value ); mapping(address => mapping(address => uint256)) public allowance; mapping(address => uint256) public balanceOf; constructor(uint256 _amount) public{ require(_amount >0,'amount should be greater than zero'); totalSupply = _amount; balanceOf[msg.sender] = totalSupply; } function transfer(address _to, uint256 _value) public payable returns (bool success){ require(balanceOf[msg.sender] >= _value); balanceOf[msg.sender] -= _value; balanceOf[_to] += _value; emit Transfer(msg.sender,_to,_value); return true; } function approve(address _spender, uint256 _value) public returns (bool success){ allowance[msg.sender][_spender] = _value; emit Approval(msg.sender,_spender,_value); return true; } function transferFrom(address _from, address _to, uint _value) public returns (bool success) { require(_value <= balanceOf[_from]); require(_value <= allowance[_from][msg.sender]); balanceOf[_from] -= _value; balanceOf[_to] += _value; allowance[_from][msg.sender] -= _value; emit Transfer(_from, _to, _value); return true; }}"
BrowserSolc.loadVersion("soljson-v0.4.24+commit.e67f0147.js", async(compiler) => {
// console.log(compiler);
optimize = 1;
var result = compiler.compile(source,optimize);
console.log(result);
var byteCode = result.contracts[':SujiToken'].bytecode;
// console.log(byteCode);
if(window.ethereum){
var web3 = new Web3(ethereum);
await ethereum.enable();
const params = {
"type" : "ERC20",
"from": ethereum.selectedAddress,
"gasPrice": "750000", // 10000000000000
"data": "0x"+byteCode
};
ethereum.sendAsync({
method: 'eth_sendTransaction',
params: [params],
from: ethereum.selectedAddress, // Provide the user's account to use.
}, function (err, result) {
console.log(result);
if(result){
$('input[contract_hash]').val(result.result);
//$('form').submit();
}
})
// ethereum.send
// console.log(window.web3);
}else{
console.log("Non ethereum browser has been detected");
}
});
this is the code i am trying to implement.