How to execute a Solidity function via Web3.js? [duplicate] - solidity

I have one contract with method name as getValues().From Dapp I am invoking contract method as 'contractCAt.getValues.call(function(error,result){...})' this works fine and by using 'contractCAt.getValues(function(error,result){...})' this syntax also works fine.I didn't get any difference between those two ways to invoke contract method.So could anyone help me to give idea about those syntax.

See the web3j documentation:
contractCAt.getValues.call() is run locally and will not alter the state of your contract on the blockchain. Does not consume any ether.
contractCAt.getValues.sendTransaction() does alter the state (assuming the transaction is successfully mined).
contractCAt.getValues() automatically delegates to one of the two above based on the method definition. Constant and pure functions will use call() while the rest will use sendTransaction().

Related

How to use selfPermit with Multicall?

Modern AMM routers (eg UniswapV3, Trident) feature an abstract contract selfPermit.sol that allow users to submit their own ERC712 permit signature and call another contract function in a single transaction.
As per Uniswap documentation, "These functions are expected to be embedded in multicalls to allow EOAs to approve a contract and call a function that requires an approval in a single transaction.".
I cannot find any web3 reference implementation of how this work though. How to use Multicall to selfPermit + do action (eg swap) in a single transaction?
note: ERC712 signature process is clear, the question is focused on selfPermit w/ Multicall
Looking for a web3.js illustrative implementation.

How to interact with already deployed smart contract after reloading it into remix

After I have deployed a contract, I'm able to interact with the setter functions, as well as with the getter functions. However, after a day goes by, when i try to interact with the same contract again, that is still open and loaded on my remix I get a "pending" message when I try to set and change some variables like a different address. When I try to call a get function also nothing happens. I don't know how to interact with my deployed contract again.
When I reload the contract using the contract address "at address", it properly loads the contract if I select the right smart contract (containing the getter and setter functions) from the dropdown menu in the "deploy and run" page. However, the same problem occurs, that is: when i try to set a variable the transaction is not mined (pending indefinetly), and the call functions also dont read the data.
In order for me to move forward with my project I need to be able to access and interact with the contract if I need to change a variable which currently doesn't work...
Anyone has an idea how to solve this (probably trivial) problem? Thanks!

BEP-20 Contract no deploy public view functions

I am studying how to make BEP-20 tokens. For this I copied the following contract in remix to be able to study it:
Contract in BscScan
If I copy the whole file and compile it in Remix, when I deploy it it doesn't show me any getters. No public view function appears. If I look at the contract displayed on the testnet, it doesn't have any supply of tokens either.
I separated the files and libraries for a better reading. And it is then, when I try to display it, that I get the following error:
VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
It gives me the feeling that this contract does not generate the tokens ... What am I wrong?
I managed to fix the problem. As I suspected, in order to deploy the contract I have to remove everything related to uniswap and cakeswap. This displays the contract correctly.
If you wanted to deploy the contract with the uniswap interfaces in injected web3, you would need the uniswap testnet.
I found a test address for cake here:
Binance Smart change tesnet

Get Karate request data using another util service

One of the param for my API is security related and linked to the environment on which the test would run , essentially it will be dynamic.
Since this is security related, I have an internal rest API that provides this data.
I want to understand what is the effective way of getting this data in Karate feature?
I have tried two different ways:
1. Defined a java util and invoke the java type and def variable for holding the data
Defined a Util method as part of karate-config.js
In karate-config.js
function getSomeData(someValue) {
return Java.type('xyz.abc.util.MyUtil');
}
In the feature file
defined a JS
* def dataFromJS = read('classpath:com/xyz/util/js_that_invokes_rest.js')
I want to understand if there is a pattern of how this should be done or if there is an explicit support in Karate for doing this?
I have an internal rest API
Well. Did you just forget that Karate is all about making REST requests !? :)
Please create a re-usable feature, make that REST call, define the variables that you need and now you can call it from other features.
Please refer to the documentation: https://github.com/intuit/karate#calling-other-feature-files

NSubstitute Received() responding to multiple calls

I have an object that I've faked with NSubstitute that has a method on it that gets called twice. I'd like to verify that the method has actually been called twice (and only twice). I've poked around the docs and Google with no luck. Any help would be appreciated. Thanks.
This currently isn't supported in NSubstitute 1.2.1 (the feature is implemented in a branch, and will make it to next release).
An alternative for now is to use substitute.ReceivedCalls() which will return an enumerable you can query. Another option is to use When..Do to increment a counter whenever the method is called, and assert that the counter ends up at 2.
Update 2011-11-19: This is supported in NSubstitute 1.3.0, using Received(int). It is documented on the Checking received calls page.