0

For Example:

I have a website and on the website there is an input box that allows the user to input a number.

Say he inputs 10, can that number then be passed to an empty variable in the smart contract?

  • read about how to develop a Dapp, in your case you need to use web3js framework. – Badr Bellaj Jul 24 '17 at 14:05
1

As @Badr Bellaj says, you can use web3.js framework.

Here is a simple example using web3.js and Metamask.

<script>
    var contractAddress = "yourContractAddress";
    var abi = JSON.parse('yourContractABI');
    var yourContract;



    window.addEventListener('load', function() {
        // Checking if Web3 has been injected by the browser (Mist/MetaMask)
        if (typeof web3 !== 'undefined') {
            window.web3 = new Web3(web3.currentProvider);
            yourContract = web3.eth.contract(abi).at(contractAddress);

        } else {
            console.log('No web3? You should consider trying MetaMask!')
        }   
     })

    //call this function when you want to pass argument to your contract function
    function callYourFunction(){
        var inputData = document.getElementById("IDInputField").value;
        //if your function is a constant function
        yourContract.yourFunction(inputData, function(error, result){
            if(!error){
                console.log(result);
            }
        });
    }

</script>

Here is a simple test contract

contract Test{

    function yourFunction(uint256 _value) constant returns (uint256) {
        return _value;
    } 
}

You can read more on:

Contract Methods - https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-methods

sendTransaction - https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendtransaction

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.