标签: smartcontracts

坚固度小数值

我需要输入用户可以支付的最小值,该值必须是例如 0.5 BNB。但我不知道该怎么做。

    uint comissionFee = 5; // 5 will represent 0,5
    uint256 minimunPay = comissionFee*100/1000;
Run Code Online (Sandbox Code Playgroud)

但返回0

  pragma solidity ^0.8.4;

  function payFees() public payable {
    require(msg.value >= 0.5); // <-- not compatible with uint256
    (bool success,) = owner.call{value: msg.value}("");
    require(success, "Failed to send money");
  }
Run Code Online (Sandbox Code Playgroud)

solidity smartcontracts

0
推荐指数
1
解决办法
8480
查看次数

进行交易时,“tx”是什么?

我是 Solidity 的初学者,我一直在玩松露,当我发送交易时,我得到一个交易日志,其中一个值是“tx”,其他标签非常不言自明,但我不太明白什么这个代表?

那么它代表什么/你可以用这些信息做什么?

谢谢

solidity smartcontracts truffle

0
推荐指数
1
解决办法
1982
查看次数

如何在 OpenZeppelin 中重写 _setupDecimals() 函数

如何覆盖 Opezeppelin 默认小数点 18。文档说 _setupDecimals() 应该从构造函数调用;我究竟做错了什么。

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {

    uint8 _decimals;

    constructor() ERC20("MyToken", "MTK") {

         _decimals = 3;

         function _setupDecimals(uint8 decimals_) internal {
            _decimals = decimals_;
         }

        _mint(msg.sender, 5000 * 10 ** decimals());

    }
}
Run Code Online (Sandbox Code Playgroud)

ethereum solidity smartcontracts

0
推荐指数
1
解决办法
830
查看次数

类型错误:ethers.Wallet.fromEncryptedJsonSync 不是构造函数

我正在尝试运行这段代码,以使用 ethers.js 库在 JS 中部署智能合约:

const ethers = require("ethers");
const fs = require("fs-extra");
require("dotenv").config();

async function main() {
  const provider = new ethers.ethers.JsonRpcProvider(process.env.RPC_URL);
  // reads the json private key from file
  const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf-8");
  
// ========= START FAILING PART ============
  let wallet = new ethers.Wallet.fromEncryptedJsonSync(
    encryptedJson,
    process.env.PRIVATE_KEY_PASSWORD
  );
// ========= END FAILING PART ============
  
  wallet = await wallet.connect(provider);
  const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf-8");
  const binary = fs.readFileSync(
    "./SimpleStorage_sol_SimpleStorage.bin",
    "utf-8"
  );
  
  const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
  console.log("Deploying, …
Run Code Online (Sandbox Code Playgroud)

javascript node.js blockchain smartcontracts ethers.js

-3
推荐指数
1
解决办法
652
查看次数