These are chat archives for ethereum/tutorials

28th
Dec 2017
我才是二亮
@2liang
Dec 28 2017 04:59
How do you do the non eth erc-20 standard token transfer operations within the contract, please? Thank you
pragma solidity ^0.4.17;



/**
 * @title ERC20Basic
 * @dev Simpler version of ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/179
 */
contract ERC20Basic {
  uint256 public totalSupply;
  function balanceOf(address who) public view returns (uint256);
  function transfer(address to, uint256 value) public returns (bool);
  event Transfer(address indexed from, address indexed to, uint256 value);
}

/**
 * @title ERC20 interface
 * @dev see https://github.com/ethereum/EIPs/issues/20
 */
contract ERC20 is ERC20Basic {
  function allowance(address owner, address spender) public view returns (uint256);
  function transferFrom(address from, address to, uint256 value) public returns (bool);
  function approve(address spender, uint256 value) public returns (bool);
  event Approval(address indexed owner, address indexed spender, uint256 value);
}

/**
 * The TrxCoin contract does this and that...
 */
contract TrxCoin {

    function transfer(address _to, uint value) public payable {
        ERC20 token = ERC20(0x1EbF4963c89A4838436Fff68F7f9B3243FdAca2D);
        require(token.approve(msg.sender, value));
        require(token.transferFrom(msg.sender, _to, value));
    }
}
The above operation shows that:The contract won't allow this transaction to be executed
thinks
vedat duymaz
@tecollo
Dec 28 2017 14:18
slmm
bunu nasıl yapacam
biri bana yardımcı olsun

pragma solidity ^0.4.16;

interface token {
function transfer(address receiver, uint amount);
}

contract Crowdsale {
address public beneficiary;
uint public fundingGoal;
uint public amountRaised;
uint public deadline;
uint public price;
token public tokenReward;
mapping(address => uint256) public balanceOf;
bool fundingGoalReached = false;
bool crowdsaleClosed = false;

event GoalReached(address recipient, uint totalAmountRaised);
event FundTransfer(address backer, uint amount, bool isContribution);

/**
 * Constrctor function
 *
 * Setup the owner
 */
function Crowdsale(
    address ifSuccessfulSendTo,
    uint fundingGoalInEthers,
    uint durationInMinutes,
    uint etherCostOfEachToken,
    address addressOfTokenUsedAsReward
) {
    beneficiary = ifSuccessfulSendTo;
    fundingGoal = fundingGoalInEthers * 1 ether;
    deadline = now + durationInMinutes * 1 minutes;
    price = etherCostOfEachToken * 1 ether;
    tokenReward = token(addressOfTokenUsedAsReward);
}

/**
 * Fallback function
 *
 * The function without name is the default function that is called whenever anyone sends funds to a contract
 */
function () payable {
    require(!crowdsaleClosed);
    uint amount = msg.value;
    balanceOf[msg.sender] += amount;
    amountRaised += amount;
    tokenReward.transfer(msg.sender, amount / price);
    FundTransfer(msg.sender, amount, true);
}

modifier afterDeadline() { if (now >= deadline) _; }

/**
 * Check if goal was reached
 *
 * Checks if the goal or time limit has been reached and ends the campaign
 */
function checkGoalReached() afterDeadline {
    if (amountRaised >= fundingGoal){
        fundingGoalReached = true;
        GoalReached(beneficiary, amountRaised);
    }
    crowdsaleClosed = true;
}


/**
 * Withdraw the funds
 *
 * Checks to see if goal or time limit has been reached, and if so, and the funding goal was reached,
 * sends the entire amount to the beneficiary. If goal was not reached, each contributor can withdraw
 * the amount they contributed.
 */
function safeWithdrawal() afterDeadline {
    if (!fundingGoalReached) {
        uint amount = balanceOf[msg.sender];
        balanceOf[msg.sender] = 0;
        if (amount > 0) {
            if (msg.sender.send(amount)) {
                FundTransfer(msg.sender, amount, false);
            } else {
                balanceOf[msg.sender] = amount;
            }
        }
    }

    if (fundingGoalReached && beneficiary == msg.sender) {
        if (beneficiary.send(amountRaised)) {
            FundTransfer(beneficiary, amountRaised, false);
        } else {
            //If we fail to send the funds to beneficiary, unlock funders balance
            fundingGoalReached = false;
        }
    }
}

}

contract token { function mintToken(address receiver, uint amount){ } }
// ...
function () {
// ...
tokenReward.mintToken(msg.sender, amount / price);
// ...
}

pragma solidity ^0.4.16;

contract owned {
address public owner;

function owned()  public {
    owner = msg.sender;
}

modifier onlyOwner {
    require(msg.sender == owner);
    _;
}

function transferOwnership(address newOwner) onlyOwner  public {
    owner = newOwner;
}

}

contract tokenRecipient {
event receivedEther(address sender, uint amount);
event receivedTokens(address _from, uint256 _value, address _token, bytes _extraData);

function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public {
    Token t = Token(_token);
    require(t.transferFrom(_from, this, _value));
    receivedTokens(_from, _value, _token, _extraData);
}

function () payable  public {
    receivedEther(msg.sender, msg.value);
}

}

interface Token {
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
}

contract Congress is owned, tokenRecipient {
// Contract Variables and events
uint public minimumQuorum;
uint public debatingPeriodInMinutes;
int public majorityMargin;
Proposal[] public proposals;
uint public numProposals;
mapping (address => uint) public memberId;
Member[] public members;

event ProposalAdded(uint proposalID, address recipient, uint amount, string description);
event Voted(uint proposalID, bool position, address voter, string justification);
event ProposalTallied(uint proposalID, int result, uint quorum, bool active);
event MembershipChanged(address member, bool isMember);
event ChangeOfRules(uint newMinimumQuorum, uint newDebatingPeriodInMinutes, int newMajorityMargin);

struct Proposal {
    address recipient;
    uint amount;
    string description;
    uint votingDeadline;
    bool executed;
    bool proposalPassed;
    uint numberOfVotes;
    int currentResult;
    bytes32 proposalHash;
    Vote[] votes;
    mapping (address => bool) voted;
}

struct Member {
    address member;
    string name;
    uint memberSince;
}

struct Vote {
    bool inSupport;
    address voter;
    string justification;
}

// Modifier that allows only shareholders to vote and create new proposals
modifier onlyMembers {
    require(memberId[msg.sender] != 0);
    _;
}

/**
 * Constructor function
 */
function Congress (
    uint minimumQuorumForProposals,
    uint minutesForDebate,
    int marginOfVotesForMajority
)  payable public {
    changeVotingRules(minimumQuorumForProposals, minutesForDebate, marginOfVotesForMajority);
    // It’s necessary to add an empty first member
    addMember(0, "");
    // and let's add the founder, to save a step later
    addMember(owner, 'founder');
}

/**
 * Add member
 *
 * Make `targetMember` a member named `memberName`
 *
 * @param targetMember ethereum address to be added
 * @param memberName public name for that member
 */
function addMember(address targetMember, string memberName) onlyOwner public {
    uint id = memberId[targetMember];
    if (id == 0) {
        memberId[targetMember] = members.length;
        id = members.length++;
    }

    members[id] = Member({member: targetMember, memberSince: now, name: memberName});
    MembershipChanged(targetMember, true);
}

/**
 * Remove member
 *
 * @notice Remove membership from `targetMember`
 *
 * @param targetMember ethereum address to be removed
 */
function removeMember(address targetMember) onlyOwner public {
    require(memberId[targetMember] != 0);

    for (uint i = memberId[targetMember]; i<members.length-1; i++){
        members[i] = members[i+1];
    }
    delete members[members.length-1];
    members.length--;
}

/**
 * Change voting rules
 *
 * Make so that proposals need tobe discussed for at least `minutesForDebate/60
John Frederic Kosanke
@kosanke
Dec 28 2017 18:38
I am building a crowdsale with the code on https://www.ethereum.org/crowdsale . I have copied the fixed supply token code to remix, but when I compile and run, the window to input the parameters is different from the one in the tutorial. Actually I don't even need to be able to change the parameters. What is the least expensive and most straightforward way to include the pre-designed contracts for the token, DAO, and crowdsale (with liquid democracy and appointee code as specified in the tutorial) in as few steps as possible?