- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能是我遗漏的一个简单错误,但我终究无法弄清楚如何在此契约(Contract)中设置 msg.value 变量。我在网上看到这个值是与交易关联的wei的数量,但是我作为合约的调用者具体怎么设置这个值。这是我正在努力处理的契约(Contract)。
实用性 0.8.7;
契约(Contract)自动售货机{
// Declare state variables of the contract
address public owner;
mapping (address => uint) public cupcakeBalances;
// When 'VendingMachine' contract is deployed:
// 1. set the deploying address as the owner of the contract
// 2. set the deployed smart contract's cupcake balance to 100
constructor() {
owner = msg.sender;
cupcakeBalances[address(this)] = 100;
}
// Allow the owner to increase the smart contract's cupcake balance
function refill(uint amount) public {
require(msg.sender == owner, "Only the owner can refill.");
cupcakeBalances[address(this)] += amount;
}
// Allow anyone to purchase cupcakes
function purchase(uint amount) public payable {
require(msg.value >= amount * 1 ether, "You must pay at least 1 ETH per cupcake");
require(cupcakeBalances[address(this)] >= amount, "Not enough cupcakes in stock to complete this purchase");
cupcakeBalances[address(this)] -= amount;
cupcakeBalances[msg.sender] += amount;
}
每次输入金额时,我都会收到“您必须为每个纸杯蛋糕支付至少 1 ETH”的错误消息
我没有地方可以具体输入我要为此支付多少的值(value),任何帮助都会很棒
here's what I'm able to input when I deploy the contract on Remix
最佳答案
关于solidity - 如何在 Remix IDE 中设置 msg.value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70936795/
我是一名优秀的程序员,十分优秀!