1

Is it possible to for a user to interact with a newly deployed instance of a contract with different parameters with the same ABI/UI

See example below;

User adds to inputs via UI (e.g 10, 0x123451234512345) and clicks submit, this prompts metamask, user deploys contract via metamask.

pragma solidity 0.4.18;

// User adds two parameters;
// Stake
// Opponent
contract Betslip {

    uint stake;
    address opponent;

    function Betslip (uint _stake, address _opponent) public {
        stake = _stake;
        opponent = _opponent;
    }

    // Rest of contract methods

}

newly deployed contract address: 0x123456789123456789123456789

User navigates to new UI and enters the newly deployed contract address (0x123456789123456789123456789) in the provided input, submits and can now use the same ABI to interact with the new contract.

1

Yes, it's totally doable. You should look at the factory pattern, where you would have something like:

pragma solidity ^0.4.4;
import './Betslip.sol';

contract BetslipFactory{
  mapping (address => Betslip) betslipMapping;

  function newBetSlip(uint _stake, address _opponent) {
    Betslip b = new Betslip(_stake, _opponent);
    betslipMapping[address(b)] = b;
  }

  function getBetSlipData(address _betslip) constant returns (address,uint8,address){

    Betslip b = betslipMapping[_betslip];
    return (address(b),b.getStake(),b.getOpponent());
  }

}

So, you would deploy BetslipFactory contract once, and then your users can interact with it by calling newBetSlip which will instantiate a new Betslip contract, and in the case above store it's address in a mapping for future access. Your users could navigate to yoursite.com/the_betslip_address and you could retrieve it's data by calling getBetSlipData and passing the betslip contract address.

You could also store the betslips in an array in the factory contract and attempt to retrieve all of them to create a list in the UI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.