-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass value, from, gasPrice to the contract method call? #988
Comments
Hi. Embark uses Web3 1.0 (currently uses beta 34), so the syntax that you used above doesn't work anymore. You need to use For your example, it would be something like so (assuming Split to be a transaction):
|
@jrainville , thanks for fast reply.
Now I am getting this. What else am I missing? var splitTransactionReceipt = null;
try
{
splitTransactionReceipt =
await splitterContractInstance.methods
.Split(firstStranger, secondStranger)
.send(
{
from : samePerson ,
value : weiToSplit ,
gasPrice: gasPriceWei
});
}
catch (ex)
{
console.log(ex);
assert.fail("unexpected exception generated by the contract" + ex);
return;
}
var splitTransactionHash = splitTransactionReceipt.tx;
var splitTransaction = await web3.eth.getTransaction(splitTransactionHash);
// the returned object of .send() does not seem to be a valid transaction ((
//
var gasUsed_bn = new BigNumber(splitTransactionReceipt.receipt.gasUsed);
var gasPrice_bn = new BigNumber(gasPriceWei); |
I also wonder : "How to trigger a fallback function of the contract?" With truffle I was invoking a await splitterContractInstance.sendTransaction(
{
from : samePerson,
value : 2000 ,
gasPrice: 0
}); |
For your first question, it is because For the second one, I'm not sure what you mean. I am not that good in Solidity. You want to make a bad transaction on the contract? |
Thanks. I'll take a look at the newer docs of |
Yeah, sort of. |
@jrainville , one final question if you don't mind... const AdkSplitterForTwo = embark.require("Embark/contracts/AdkSplitterForTwo");
var splitterContractInstance =
await AdkSplitterForTwo.deploy({ arguments: [] }).send(); I am trying to deploy the contract instance explicitly in a test. For some reason, I am getting a different behaviour comparing to the case when I use a global contract deployed by embark Could you please suggest a piece of documentation I can look at to resolve this kind of errors? P.S. Sorry if this entire thread was irrelevant and it was a wrong place to ask. And thank you for your time and patience. |
If you wish to execute the fallback function for a contract with web3js, you could do something like this:
|
For the contract deploy, here is the exact Embark doc for that: |
@jrainville , thank you for the link.
|
@richard-ramos , thanks I'll give that API a try. |
@jrainville , @richard-ramos so I have applied your suggestions. My tests do compile and run properly. Still, the balance bookkeeping fails since
Here are my logs : Any suggestions, please? |
UPD: Seems like I am experiencing this issue of |
Can you try this workaround web3/web3.js#1458 (comment)? |
Yeah. It works. I also had an issue with event log assertions since the logs array has turned out to be a dictionary. But I've figured things out using the |
My brief summary of porting the contract to web3.js v1.01). Transaction options are now passed to await splitterContractInstance.Split(firstStranger, secondStranger).send({
from : samePerson ,
value : weiToSplit ,
gasPrice: gasPriceWei
}); 2). 3). 4). Contract method call produces transaction receipt only in web3.js v1.0. The name has been changed to |
Sorry to add to this closed thread, but I didn't find anything related elsewhere. |
@MunhozThiago, sorry, I can't really answer your question. Maybe one of the devs of Web3js would know more https://github.com/ethereum/web3.js/issues |
Overview
How to pass value, from, gasPrice to the contract method call?
The
web3.js
API do not seem to work for me.This code works for my contract under
truffle
but I'm getting test failures underembark
since no ether is being sent.Extra Detail
Initialization in embark test :
Initialization in truffle test
My embark project https://github.com/dodikk/eth-splitter-contract-exercise-embark
My truffle project https://github.com/dodikk/eth-splitter-contract-exercise
Steps to reproduce
git clone https://github.com/dodikk/eth-splitter-contract-exercise-embark
embark test
Expected result : all tests pass
Actual result : 4 tests fail due to an exception in
sendTransaction
. The contract gets reverted due to insufficient ether amount even though I am trying to send some wei.Screenshots
N/A
Logs
--logfile log.txt
for some reason this option does not work for me when I invokeembark test
. Any suggestions appreciatedContext (Environment)
The text was updated successfully, but these errors were encountered: