0

Currently in Truffle I'm passing in value manually, but how do I make this value something I require. For example when I want to make a transaction on MetaMask, there's a transaction that appears requesting x value and I approve it. How would I request value from the user? I want to deploy and test this contract on Rinkeby.

TokenSaleContract.at(this.props.address)
        .then(instance => {
            contractInstance = instance;
            contractInstance.buyToken(2, {value: 507087936329796580})
            return c.numberOfTokensFromAddress('0x...')
        })
        .then(numberOfTokens => {
            console.log(`You (0x...) now have ${numberOfTokens}`);
        })
  • When you say "in Truffle", do you mean you are using Truffle console, right? – Luiz Soares Dec 8 '17 at 22:07
  • I mean I'm using truffle-contract – JorahFriendzone Dec 8 '17 at 22:43
1

You can use a library like readline-sync to get user input (source):

var readlineSync = require('readline-sync');

// Wait for user's response. 
var userName = readlineSync.question('May I have your name? ');
console.log('Hi ' + userName + '!');

Note: Do not forget to install the package first, for example yarn add readline-sync.

  • I'm trying to not require user to input the data, but rather have the value amount sent to the user – JorahFriendzone Dec 8 '17 at 22:44
  • What 'value' are you referring to? You can send ether using web3.eth.sendTransaction. – lunr Dec 8 '17 at 22:46
  • I'm talking about this line contractInstance.buyToken(2, {value: 507087936329796580} I want to have the value passed to the buyer – JorahFriendzone Dec 8 '17 at 23:18

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.