I am currently using Brownie to learn smart contract and blockchain development. I am having trouble understanding how to call functions and check value of variables from smart contracts using python script. How would I be able to do this?
Below I have a contract DutchAuction
where I have defined a function bid()
which returns 'Hello world'
just for testing purposes that I am trying to call.
pragma solidity ^0.8.10;
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
contract DutchAuction {
uint public startTime;
uint public endTime;
uint public price;
uint public startPrice;
address public assetOwner;
constructor(uint _startPrice, uint _endTime) public {
startTime = block.timestamp;
price = _startPrice;
startPrice = _startPrice;
endTime = _endTime;
assetOwner = msg.sender;
}
function bid() public returns (string calldata) {
return 'hello world';
}
}
Change the string calldata
to string memory
in your bid()
function returns
statement.
The string literal is loaded to memory (not to calldata) and then returned.
If you wanted to return calldata
, you'd need to pass the value as calldata first:
function foo(string calldata _str) public pure returns (string calldata) {
return _str;
}
Docs: https://docs.soliditylang.org/en/v0.8.10/types.html#data-location