Solidity calling payable function with arguments with hardhat ethers.js - solidity

I'm testing this function:
function Deposit(uint256 StopLoss) public payable {//Deposita quantity i es registre
//Pay subscription
if (msg.value == 0){
revert Quantity_zero();
}
//Add wallet to the s_Wallets
s_Wallets.push(payable(msg.sender));
//Start subscription time
Dades storage dades = s_Registre[msg.sender];
dades.Quantity += msg.value;
dades.Stop = StopLoss;
}
When sending value and StopLoss argument it allways send me some error.
This is the js testing code being 1850 the argument StopLoss value and sending a 5 ETH value.
describe("Subscription", async function () {//PriceConversion
it("Subscribes the deployer", async function () {
await MarketOrder.Deposit(1850, {value: ethers.utils.parseEther("5")})
const Quantity = await MarketOrder.CallQuantity()
console.log(`Q: ${Quantity}`)
const Stop = await MarketOrder.CallStop()
console.log(`S: ${Stop}`)
assert.equal(Quantity.toString(), 1850)
assert.equal(Stop.toString(), 5)
}
})
This is the error:
1) MarketOrder Unit Tests
Subscription
Subscribes the deployer:
Error: invalid BigNumber value (argument="value", value=[1850], code=INVALID_ARGUMENT, version=bignumber/5.6.2)
at Logger.makeError (node_modules/#ethersproject/logger/src.ts/index.ts:261:28)
at Logger.throwError (node_modules/#ethersproject/logger/src.ts/index.ts:273:20)
at Logger.throwArgumentError (node_modules/#ethersproject/logger/src.ts/index.ts:277:21)
at Function.BigNumber.from (node_modules/#ethersproject/bignumber/src.ts/bignumber.ts:289:23)
at NumberCoder.encode (node_modules/#ethersproject/abi/src.ts/coders/number.ts:25:27)
at /home/oriok/hh-ff/1.uniswapV3/node_modules/#ethersproject/abi/src.ts/coders/array.ts:71:19
at Array.forEach (<anonymous>)
at pack (node_modules/#ethersproject/abi/src.ts/coders/array.ts:54:12)
at TupleCoder.encode (node_modules/#ethersproject/abi/src.ts/coders/tuple.ts:54:20)
at AbiCoder.encode (node_modules/#ethersproject/abi/src.ts/abi-coder.ts:111:15)
error Command failed with exit code 1.
Does anyone know how to send argument + value properly?? I have tryed many codes but not working.
Ty guys!

ethers.utils.parseEther returns object with BigNumber in it..
you have to convert it into string before using it in the test..
Eg:
ethers.utils.parseEther("5").toString()
Refer.. https://docs.ethers.io/v5/api/utils/display-logic/#utils-parseEther

Related

Tezos LIGO send tezos from contract to an address using jsLigo

I am going to send tezos from contract to an address using jsLigo
if (amount > (0 as tez)) {
let receiver: contract<unit> =
match ((Tezos.get_contract_opt(sender) as option<contract<unit>>), {
Some: (contract) => contract,
None: () => failwith("Contract not found.")
});
Tezos.transaction(unit, (amount as tez), receiver);
}
I am getting this error while building.
Invalid type(s)
Cannot unify operation with unit.
And I am not sure it is correct method to send tezos.

Crowd Sale Contract Issue while minting token

I am currently working on a crowd sale contract, But I am having an issue with a function as the list of the error and the code of the function is attached, I need someone to tell me that what is happening in the code and how can i resolve the error that I'm facing in the code. Solidity version ^0.5.0
Code:
function _finalization() internal {
if (goalReached()) {
ERC20Mintable erc20Mintable = ERC20Mintable(token);
//getting the total tokens that are been minted yet
uint256 alreadyMintedToken = erc20Mintable.totalSupply();
//tokens of the final total supply
uint256 finalTotalTokenSupply = alreadyMintedToken
.div(tokenSalePercentage)
.mul(100);
foundersTimelock = new TokenTimelock(
token,
foundersFund,
releaseTime
);
partnersTimelock = new TokenTimelock(
token,
foundersFund,
releaseTime
);
foundationTimelock = new TokenTimelock(
token,
foundersFund,
releaseTime
);
//we will have the tokens that the founder will get
erc20Mintable.mint(
address(foundersTimelock),
finalTotalTokenSupply.mul(foundersPercentage).div(100)
);
erc20Mintable.mint(
address(partnersTimelock),
finalTotalTokenSupply.mul(partnersPercentage).div(100)
);
erc20Mintable.mint(
address(foundationTimelock),
finalTotalTokenSupply.mul(foundationPercentage).div(100)
);
erc20Mintable.renounceMinter();
// Unpause the token
ERC20Pausable erc20Pausable = new ERC20Pausable(token);
erc20Pausable.unpause();
erc20Pausable.renounceOwnership(wallet);
}
super._finalization();
}
Error 1:
Explicit type conversion not allowed from "function () view returns
(contract IERC20)" to "contract ERC20Mintable". ERC20Mintable
erc20Mintable = ERC20Mintable(token);
Error 2:
Crowdsale.sol:179:46: TypeError: Invalid type for argument in function call. Invalid implicit conversion from function () view returns (contract IERC20) to contract IERC20 requested.
foundersTimelock = new TokenTimelock(token,foundersFund,releaseTime);
^---^
Error 3:
Crowdsale.sol:179:28: TypeError: Type contract TokenTimelock is not
implicitly convertible to expected type address. foundersTimelock =
new TokenTimelock(token,foundersFund,releaseTime);

Fail to swap ETH to dai using uniswap sdk with web3.js

I am coming across an issue swapping weth to dai using uniswap Node.js SDK with web3.js.
My code is below:
const dai = await Fetcher.fetchTokenData(net, daiAddress);
const weth = await Fetcher.fetchTokenData(net, wethAddress);
const pair = await Fetcher.fetchPairData(dai, weth);
const route = new Route([pair], weth);
console.log(route.midPrice.toSignificant(6))
console.log(route.midPrice.invert().toSignificant(6))
const trade = new Trade(route, new TokenAmount(weth, "1000000000000000000"), TradeType.EXACT_INPUT)
console.log(trade.executionPrice.toSignificant(6))
const slippageTollerance = new Percent("10", "10000")
const amountOutMin = trade.minimumAmountOut(slippageTollerance)
// const amountOutMin = web3.current.utils.toBN(amountOutMinRaw)
const path = [weth.address, dai.address]
const deadline = Math.floor(Date.now() / 1000 ) + 60*20
const amountIn = trade.inputAmount.raw
const to = ""
uniSwapRouter.current = new web3.current.eth.Contract(
uniRouterAbi,
"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
);
const tx = await uniSwapRouter.current.methods.swapExactETHForTokens(
// amountIn,
1,
to,
path,
deadline
).send({
from:accounts[0],
gasLimit: 8000000,
gasPrice: web3.current.utils.toWei('100', 'Gwei'),
value: web3.current.utils.toWei('1', 'Ether')
})
console.log(tx.hash)
And it turns error:
Unhandled Rejection (Error): expected array value (argument="path", value="", code=INVALID_ARGUMENT, version=abi/5.0.7)
Anyone helps let me know which part I mess up. I have been struggling with it for two days.
I am running it on kovan testnet and I am sure that I have some DAI(11.647) & ETH(2.4845) in my kovan metamask wallet.
I think I found out where the thing gone wrong.
The deadline might be too short to go through the transaction.
It turned out ok after expending the deadline.

Vue.js Nuxt - cannot access Array (value evaluated upon first expanding error)

I have the following function which gives me an array called URLs
const storageRef = this.$fire.storage.ref().child(fileName)
try {
const snapshot = storageRef.put(element).then((snapshot) => {
snapshot.ref.getDownloadURL().then((url) => {
urls.push(url)
})
})
console.log('File uploaded.')
} catch (e) {
console.log(e.message)
}
});
console.log(urls)
console.log("about to run enter time with imageurls length " + urls.length)
When I run console.log(URLs) initially I do see the array like the following
[]
0: "testvalue"
length: 1
__proto__: Array(0)
However, there is a small information icon stating
This value was evaluated upon first expanding. The value may have changed since.
Because of this, when I try to get the length of URLs, I get zero, meaning the value is being updated.
Does anyone know what's happening? I am using Vue.JS/Nuxt.

How do I send data to a process?

I'm trying to write a dart server application that will communicate to an application which accepts input and gives output, like the unix tool bc.
I can read the output of bc, but I cannot send a command to bc. Here is my code:
#import('dart:io');
void main() {
var p = Process.start('bc', ["-i"]);
var stdoutStream = new StringInputStream(p.stdout);
stdoutStream.onLine = () => print(stdoutStream.readLine());
p.stdin.writeString("quit\n");
p.onExit = (exitCode) {
print('exit code: $exitCode');
p.close();
};
}
When I run it, I get the following error:
Unhandled exception:
SocketIOException: writeList failed - invalid socket handle
0. Function: '_Socket#14117cc4.writeList' url: 'dart:io' line:4808 col:48
1. Function: '_SocketOutputStream#14117cc4._write#14117cc4' url: 'dart:io' line:4993 col:70
2. Function: '_SocketOutputStream#14117cc4.write' url: 'dart:io' line:4969 col:29
3. Function: '_BaseOutputStream#14117cc4.writeString' url: 'dart:io' line:5197 col:3
4. Function: '::main' url: 'file:///var/www/html/example.dart' line:8 col:22
If I comment out the line where I try to write "quit\n", then it runs and I can see the output of bc.
So how do I get my program to send commands to an application on my server like bc?
The problem is that you're writing to stdin before the process has properly started. Try:
#import('dart:io');
void main() {
var p = Process.start('bc', ["-i"]);
var stdoutStream = new StringInputStream(p.stdout);
stdoutStream.onLine = () => print(stdoutStream.readLine());
p.onStart = () => p.stdin.writeString("1+1\nquit\n");
p.onExit = (exitCode) {
print('exit code: $exitCode');
p.close();
};
}