contracts/3_Ballot.sol:33:37: TypeError: Named argument does not match function declaration - solidity

from solidity:
contracts/3_Ballot.sol:33:37: TypeError: Named argument does not match function declaration.
Request memory newRequest = Request({
^ (Relevant source part starts here and spans across multiple lines).
I get this error every time. What should i do for the solve it?
pragma solidity ^0.4.17;
contract Campaign {
struct Request {
string description;
uint value;
address recipient;
bool complete;
}
Request[] public requests;
address public manager;
uint public minimumContirbution;
address[] public approvers;
modifier restricted() {
require (msg.sender == manager);
_;
}
function Campaign (uint minimum) public {
manager = msg.sender;
minimumContirbution = minimum;
}
function contribute () public payable {
require(msg.value > minimumContirbution);
approvers.push(msg.sender);
}
function createRequest(string description, uint value, address recipient) restricted public {
Request memory newRequest = Request({
description: description,
value: value,
restricted: restricted,
complete: false
});
requests.push(newRequest);
}
}

You can define the Request struct in this way and push it into requests array:
function createRequest(string description, uint value, address recipient) restricted public {
Request memory newRequest = Request(description, value, recipient, false);
requests.push(newRequest);
}
In this way, you can add the struct into your array and can retrieve with all parameters setted previously.

Because you're are using wrong argument(restricted) inside you Request type
try this:
Request memory newRequest = Request({
descritption: descritpion,
value: value,
recipient: recipient,
complete: false
});

Related

TypeError: Member "mint" not found or not visible after argument-dependent lookup in address

I'm trying to compile this contract but it won't work. I know I can point mint and redeem for address, but since I'll get these from compound, how do I point it to make it compile?
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;
import "#openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import "#openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import {OwnableUpgradeable} from "#openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
contract Myvaultis ERC4626Upgradeable, OwnableUpgradeable {
//compound variable to store address
address _cAsset;
function initialize(
IERC20MetadataUpgradeable asset_,
string memory name_,
string memory symbol_
) public initializer {
__MyVault_init(asset_, name_, symbol_);
_cAsset = 0x00000000000000000000000; //put here cAsset address
}
function __MyVault_init(
IERC20MetadataUpgradeable asset_,
string memory name_,
string memory symbol_
) internal onlyInitializing {
__ERC4626_init_unchained(asset_);
__ERC20_init_unchained(name_, symbol_);
__Ownable_init_unchained();
}
function depositCompound(
IERC20MetadataUpgradeable asset_,
address cAsset_,
uint256 _amount
) public onlyOwner returns (uint) {
asset_.approve(cAsset_, _amount);
// Mint cTokens
uint mintResult = cAsset_.mint(_amount);
return mintResult;
}
function withdrawCompound(
uint256 amount,
bool redeemType,
address cAsset_
) public onlyOwner returns (bool) {
uint256 redeemResult;
if (redeemType == true) {
redeemResult = cAsset_.redeem(amount);
} else {
redeemResult = cAsset_.redeemUnderlying(amount);
}
return true;
}
}
The error i'm getting is
TypeError: Member "mint" not found or not visible after argument-dependent lookup in address.
|
38 | uint mintResult = cAsset_.mint(_amount);
| ^^^^^^^^^^^^
Error HH600: Compilation failed
looks like you haven't defined the contract and your trying to access it via the address.
You might have to define the interface then plug in the address.
contract = interface(address)
then you can use contract.functionName(parameters)

CONTRACT_REVERT_EXECUTED Hedera Smart Contract

CONTRACT_REVERT_EXECUTED
Not sure what I'm doing wrong but I'm trying to call a function and it takes in one parameter and I made sure it was correct but it still reverts. This is hedera-hashgraph using HederaTokenService.
Smart Contract:
pragma solidity ^0.8.11;
import "./hip-206/HederaTokenService.sol";
import "./hip-206/HederaResponseCodes.sol";
contract Minting is HederaTokenService {
address tokenAddress;
bytes metadata;
string baseURI = "abc";
uint64 mintPrice;
function mintNonFungibleToken(uint64 _amount) external payable {
bytes[] memory nftMetadatas = generateBytesArrayForHTS(
baseURI,
_amount
);
(
int256 response,
uint64 newTotalSupply,
) = HederaTokenService.mintToken(tokenAddress, _amount, metadata);
if (response != HederaResponseCodes.SUCCESS) {
revert("Mint Failed");
}
}
// #dev Helper function which generates array of addresses required for HTSPrecompiled
function generateAddressArrayForHTS(address _address, uint256 _items)
internal
pure
returns (address[] memory _addresses)
{
_addresses = new address[](_items);
for (uint256 i = 0; i < _items; i++) {
_addresses[i] = _address;
}
}
// #dev Helper function which generates array required for metadata by HTSPrecompiled
function generateBytesArrayForHTS(bytes memory _bytes, uint256 _items)
internal
pure
returns (bytes[] memory _bytesArray)
{
_bytesArray = new bytes[](_items);
for (uint256 i = 0; i < _items; i++) {
_bytesArray[i] = _bytes;
}
}
Calling the transaction in js:
const contractMint = await new ContractExecuteTransaction()
.setContractId(contractId)
.setGas(3000000)
.setFunction(
"mintFungibleToken",
new ContractFunctionParameters().addUint64(1)
)
.setMaxTransactionFee(new Hbar(2));
Also note that a REVERT does usually contain useful information, you can navigate to hashscan.io to look up the response from your smart contract, for example
https://hashscan.io/testnet/transaction/1675427464.278782297?tid=0.0.1189-1675427451-309271560
shows a contract that reverted, the error message is 0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b52656d697420746f6b656e20616c726561647920637265617465640000000000
with the error message starting with 0x08c379a, we know it's a string, so we can decode it
Hacky way:
Navigate to: https://www.rapidtables.com/convert/number/hex-to-ascii.html
Paste the above (remove the 0x)
Choose ASCII for character encoding
Press convert
Output: Ãy  Remit token already created
In Javascript
const {ethers} = require("ethers");
async function main() {
const error = "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b52656d697420746f6b656e20616c726561647920637265617465640000000000";
const reason = ethers.utils.defaultAbiCoder.decode(
['string'],
ethers.utils.hexDataSlice(error, 4)
)
console.log(reason);
};
void main();
It looks like you're trying to call mintFungibleToken from JS, but the smart contract doesn't have a mintFungibleToken function; the smart contract function name is mintNonFungibleToken.

Solidity - Simple API request - Undeclared identifier problem

I am new in Solidity and currently, I am trying to deploy a simple smart contract that requests ETH price "LOWDAY", and "HIGHDAY". I already did a very similar SC that requests only "VOLUME24HOUR" and it worked great. This is the error that I get:
contracts/API_Consumer_Info.sol:24:66: DeclarationError: Undeclared
identifier. Did you mean "jobID"? Chainlink.Request memory request =
buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
^---^
pragma solidity ^0.6.7;
import "#chainlink/contracts/src/v0.6/ChainlinkClient.sol";
contract APIConsumerInfo is ChainlinkClient
{
uint256 public lowDay;
uint256 public highDay;
address private oracle;
bytes32 private jobID;
uint256 private fee;
constructor() public
{
setPublicChainlinkToken();
oracle = 0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e;
jobID = "29fa9aa13bf1468788b7cc4a500a45b8";
fee = 0.1 * 10 ** 18;
}
function requestLowDay() public returns (bytes32 requestID)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); //Error occur here
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
request.add("path", "RAW.ETH.USD.LOWDAY");
int timesAmount = 10**2;
request.addInt("times", timesAmount);
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfill(bytes32 _requestId, uint256 _dayLow) public recordChainlinkFulfillment(_requestId)
{
lowDay = _dayLow;
}
function requestHighDay() public returns (bytes32 requestID)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector); //Error occur here
request.add("get", "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD");
request.add("path", "RAW.ETH.USD.HIGHDAY");
int timesAmount = 10**2;
request.addInt("times", timesAmount);
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfill(bytes32 _requestId, uint256 _dayHigh) public recordChainlinkFulfillment(_requestId)
{
highDay = _dayHigh;
}
function withdrawLink() external
{
LinkTokenInterface linkToken = LinkTokenInterface(chainlinkTokenAddress());
require(linkToken.transfer(msg.sender, linkToken.balanceOf(address(this))), "Unable to transfer");
}
}
The base code is not written by my and it works perfectly with "VOLUME24HOUR" call. When I did the necessary changes to request.add("path") and added new variable lowDay/highDay it started to throw error.
Thank you ʕっ•ᴥ•ʔっ
Solidity variable names are case-sensitive.
You have defined a bytes32 property named jobID (uppercase D) but then you're trying to pass jobId (lowercase d).
Solution: Pass the correct case-sensitive variable name. In your case jobID.

_signTypedData method on ethers does not match with ERC712 solidity code

I've faced an ethers signature unmatched problem.
Everything is normal.
Already compared domainData, types, message variable in the js code with contract.
Below is the JS Code to generate signature and call contract.
const contractAddress = await contract.address;
domainData.chainId = 31337;
domainData.verifyingContract = contractAddress;
const signature = await signer._signTypedData(domainData, types, message);
const { r, s, v } = ethers.utils.splitSignature(signature);
const result = await contract.recoverAddressFromTypedData(
message,
v,
r,
s
);
expect(result).to.equal(signer.address);
Below is the solidity code which use "#openzeppelin/contracts/utils/cryptography/draft-EIP712.sol"
function recoverAddressFromTypedData(
Bid memory bid,
uint8 v,
bytes32 r,
bytes32 s
) public view returns (address) {
bytes32 digest = _hashTypedDataV4(hashBid(bid));
address signer = ecrecover(digest, v, r, s);
return signer;
}
But I got following error on the last line of JS code.
AssertionError: expected '0x7Da34C07B95dB4A1c85fe4C5d313F4860E85e340' to equal '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
+ expected - actual
-0x7Da34C07B95dB4A1c85fe4C5d313F4860E85e340
+0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
Is there anything wrong with my code?
I don't know if I have the same reason as you, in my case I had a struct member containing a string type which needed to be converted to bytes32.
contract MyContract is Ownable, AccessControl, EIP712 {
struct Action {
address initiator;
string name;
}
bytes32 public constant ACTION_TYPE_HASH = keccak256("Action(address initiator,string name)");
function _hashStruct(Action memory action) private pure returns (bytes32) {
// If your struct member has string type,
// you need to use keccak256(abi.encodePacked(string))
// convert it to bytes32
return keccak256(abi.encode(ACTION_TYPE_HASH, action.initiator, keccak256(abi.encodePacked(action.name))));
}
function _hashTypedDataV4(Action memory action) private view returns (bytes32) {
bytes32 structHash = _hashStruct(action);
return EIP712._hashTypedDataV4(structHash);
}
// more...
}

Transfer ownership web3

I am creating a dapp to transfer ownership of the contract from one address to another using testrpc. However,I keep encountering this problem. I have tried using sentransaction method to do perform this ownership change.Perhaps I'm calling the exchange in a wrong manner.
Solidity version 0.4.4
web3 "version": "0.20.2"
web3.js:3127 Uncaught Error: VM Exception while processing transaction: invalid opcode
at Object.InvalidResponse (web3.js:3127)
at RequestManager.send (web3.js:6332)
at Eth.send [as sendTransaction] (web3.js:5066)
at SolidityFunction.sendTransaction (web3.js:4122)
at SolidityFunction.execute (web3.js:4208)
at transferOwnership (luxcure_manu.html:309)
at HTMLButtonElement.onclick (luxcure_manu.html:378
Full solidity contract as of yet.
pragma solidity ^0.4.4;
// TODO: Hash of the cert through IPFS Hash
// Transfer ownership of smart contract
contract LuxSecure {
address public contract_owner; //Manufacturer/owner
//string public current_owner; //Current Owner of good
bytes32 public model; //Model
mapping(uint => address) public owners; //list of owners
uint256 public owners_count;
bytes32 public status; // (Public(Owned by no one), Private(Bought by another entity),stolen(Stolen from public or private))
bytes32 public date_manufactured; //Time
// Set manufacturer of the Good RUN ONCE ONLY
function manufacturer() public{
if(owners_count == 0){
contract_owner = msg.sender;
}
}
//Modifier that only allows owner of the bag to Smart Contract AKA Good to use the function
modifier onlyOwner(){
require(msg.sender == contract_owner);
_;
}
// Add a new product to the blockchain with a new serial
function addNewGoods(bytes32 _model,bytes32 _status, bytes32 _date_manufactured) public returns(bool made) {//Declare Goods struct
setOwner(msg.sender);
model = _model;
status = _status;
date_manufactured = _date_manufactured;
return true;
}
//This function transfer ownership of contract from one entity to another
function transferOwnership(address _newOwner) public onlyOwner(){
require(_newOwner != address(0));
contract_owner = _newOwner;
}
//Set the KEY to uint256 and VALUE owner Ethereum Address
function setOwner(address owner)public{
owners_count += 1 ;
owners[owners_count] = owner;
}
//Get the previous owner in the mappings
function previousOwner()constant public returns(address){
if(owners_count != 0){
uint256 previous_owner = owners_count - 1;
return owners[previous_owner];
}
}
// Getter Methods
function getManufacturer() constant public returns(address){
return contract_owner;
}
function getCurrentOwner() constant public returns(address){
return owners[owners_count] ;
}
function getOwnerCount() constant public returns(uint256){
return owners_count;
}
function getModel() constant public returns(bytes32){
return model;
}
function getStatus() constant public returns(bytes32){
return status;
}
function getDateManufactured() constant public returns(bytes32){
return date_manufactured;
}
}// end of LuxSecure
Javascript to perform the transfer of ownership
function transferOwnership(){
var account_to_transfer = document.getElementById("ethereumaddress").value;
contract.transferOwnership(account_to_transfer,{
from:web3.eth.accounts[0],
gas:4000000
});
}
I don't see any particular mistake in your code. Maybe a bad formatting on the front-side, but can't guess for sure as we have partial front here.
I don't know if it will be some help but sometimes, using truffle, it happened to me to have some functions that returned bad opcode from testrpc/ganache-cli while no apparent error was in the code.
Deleting the ABI, recompiling the smart-contracts to get a brand new ABI and then redeploying the contracts solved the problem.