I am newbie in solidity. I don't understand what steps I must do for deploy contract in the Ropsten test-net.
This is my contract:
pragma solidity ^0.4.15;
import './ERC20.sol';
import './SafeMath.sol';
contract StepanToken2 is ERC20{
using SafeMath for uint256;
address public ownerFirst;
address public ownerSecond;
string public constant name = "Stepan Token";
string public constant symbol = "SPT";
uint8 public constant decimals = 8;
uint totalTokens = 100000000000000;
//balances for accaunts
mapping(address => uint) balances;
//Owner of account approves the transfer of an amount to another account
mapping(address => mapping(address => uint)) allowed;
function StepanToken2 (address _ownerFirst, address _ownerSecond){
ownerFirst = _ownerFirst;
ownerSecond = _ownerSecond;
balances[ownerFirst] = SafeMath.div(totalTokens, 3);
balances[ownerSecond] = SafeMath.sub(totalTokens, balances[ownerFirst]);
}
function totalSupply() constant returns (uint256 totalSupply){
return totalTokens;
}
function balanceOf(address _owner) constant returns (uint256 balance){
return balances[_owner];
}
function transfer(address _to, uint _value) returns (bool success){
require(balances[msg.sender] >= _value && _value > 0 && SafeMath.add(balances[_to], _value) > balances[_to]);
balances[msg.sender] = SafeMath.sub(balances[msg.sender],_value);
balances[_to] = SafeMath.add(balances[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint _value) returns (bool success){
require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0 && SafeMath.add(balances[_to], _value) > 0);
balances[_from] = SafeMath.sub(balances[_from], _value);
allowed[_from][msg.sender] = SafeMath.sub(allowed[_from][msg.sender], _value);
balances[_to] = SafeMath.add(balances[_to], _value);
Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint _value) returns (bool success){
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining){
return allowed[_owner][_spender];
}
}
And it compiles and migrates normal. When contract will compiling in ropsten I should set parameters in constructor contract. I have created an HTML file with JS for this contract:
var Web3 = require('web3'); var web3 = new Web3();
function initConnectWeb3() {
web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/[infura_api_key]"));
console.log(web3);
}
initConnectWeb3();
primaryAddress = web3.eth.accounts[0];
var MyContract = web3.eth.contract([{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [{
"name": "",
"type": "string"
}],
"payable": false,
"type": "function"
},
{
"constant": false,
"inputs": [{
"name": "_spender",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [{
"name": "success",
"type": "bool"
}],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [{
"name": "totalSupply",
"type": "uint256"
}],
"payable": false,
"type": "function"
},
{
"constant": false,
"inputs": [{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [{
"name": "success",
"type": "bool"
}],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [{
"name": "",
"type": "uint8"
}],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ownerFirst",
"outputs": [{
"name": "",
"type": "address"
}],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [{
"name": "_owner",
"type": "address"
}],
"name": "balanceOf",
"outputs": [{
"name": "balance",
"type": "uint256"
}],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [{
"name": "",
"type": "string"
}],
"payable": false,
"type": "function"
},
{
"constant": false,
"inputs": [{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [{
"name": "success",
"type": "bool"
}],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [{
"name": "_owner",
"type": "address"
},
{
"name": "_spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [{
"name": "remaining",
"type": "uint256"
}],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ownerSecond",
"outputs": [{
"name": "",
"type": "address"
}],
"payable": false,
"type": "function"
},
{
"inputs": [{
"name": "_ownerFirst",
"type": "address"
},
{
"name": "_ownerSecond",
"type": "address"
}
],
"payable": false,
"type": "constructor"
},
{
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_from",
"type": "address"
},
{
"indexed": true,
"name": "_to",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [{
"indexed": true,
"name": "_owner",
"type": "address"
},
{
"indexed": true,
"name": "_spender",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
}
]);
// contact = MyContract.new(0xC0b4ec83028307053Fbe8d00ba4372384fe4b52B, 0x4E90a36B45879F5baE71B57Ad525e817aFA54890, {from: primaryAddress, gas: 50000});
contract = MyContract.new("0xC0b4ec83028307053Fbe8d00ba4372384fe4b52B", "0x4E90a36B45879F5baE71B57Ad525e817aFA54890", {
from: primaryAddress,
gas: 50000
// data: evmCode
}, function (err, contract) {
if (!err && contract.address)
console.log(contract.address);
});
I have added changes to my script