1

I'm using truffle and metamask to deploy a very simple contract that enables the transfer of ether from one test account to another.

How do I use my JavaScript file to access the options parameters that were passed in during deployment? Can the constructor parameters passed in during deployment be modified afterwards?

Here's the line in 2_deploy_contracts.js:

deployer.deploy(EscrowPayment, web3.eth.accounts[1], web3.eth.accounts[2], {gas: 4400000, value: web3.toWei(20, 'ether')});

The options parameter would be {gas: 4400000, value: web3.toWei(20, 'ether')}

Here's the constructor in the contract:

function EscrowPayment(address _seller, address _judge) payable {
    buyer = msg.sender;
    seller = _seller;
    judge = _judge;
}

I read this documentation but wasn't able to do something like "myContract.options"

0

The options that you are passing in the last json object are: gaslimit and value of Ether to send along. These (and other configurable parameters such as the sender or the gasprice) are available via msg and tx objects as described here:

function EscrowPayment(address _seller, address _judge) payable {
    gasLimit = msg.gas; // this is only the *remaining* gas and not the exact value that you passed
    value = msg.value; // in Wei
    gasPrice = tx.gasprice;
    buyer = msg.sender;
    seller = _seller;
    judge = _judge;
}
  • Thank you! Very helpful. I was also wondering, can we still change the variables such as seller after the contract is deployed? – jwu Jun 20 '17 at 20:03
  • you cannot - unless you provide a function for it (and then everyone seeing your contract can see its modifiable). That is the power of smart contracts really, btw with this deep realization you understand more of blockchain than 99.9% of people out there :) – Validity Labs - Sebastian Jun 21 '17 at 11:44
  • @juwu if this is helpful then consider accepting my answer with the green checkmark button :) – Validity Labs - Sebastian Jun 21 '17 at 11:49

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.