标签: solidity

如何在智能合约中接收和发送USDT?

是否有任何指南或代码可以作为示例来实现智能合约接收和发送 USDT 到其他地址的功能。

我感谢您的帮助

ethereum solidity

13
推荐指数
1
解决办法
2万
查看次数

ValueError:不支持方法 eth_maxPriorityFeePerGas,带有 ganache 的 web3.py

我正在运行以下代码web3.py

transaction = SimpleStorage.constructor().buildTransaction(
    {"chainId": chain_id, "from": my_address, "nonce": nonce}
)
Run Code Online (Sandbox Code Playgroud)

我遇到了以下错误:

Traceback (most recent call last):
  File "/Users/patrick/code/web3_py_simple_storage/deploy.py", line 64, in <module>
    transaction = SimpleStorage.constructor().buildTransaction(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eth_utils/decorators.py", line 18, in _wrapper
    return self.method(obj, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/contract.py", line 684, in buildTransaction
    return fill_transaction_defaults(self.web3, built_transaction)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/_utils/transactions.py", line 121, in fill_transaction_defaults
    default_val = default_getter(web3, transaction)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/_utils/transactions.py", line 71, in <lambda>
    web3.eth.max_priority_fee + (2 * web3.eth.get_block('latest')['baseFeePerGas'])
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/web3/eth.py", line 549, in max_priority_fee …
Run Code Online (Sandbox Code Playgroud)

python ethereum solidity ganache

13
推荐指数
1
解决办法
3086
查看次数

该交易声明链 ID 5777,但连接的节点位于 1337

我正在尝试通过使用 python 进行交易,将我的 SimpleStorage.sol 合约部署到 ganache 本地链。连接到链条似乎有问题。

from solcx import compile_standard
from web3 import Web3
import json
import os
from dotenv import load_dotenv

load_dotenv()

with open("./SimpleStorage.sol", "r") as file:
    simple_storage_file = file.read()

compiled_sol = compile_standard(
    {
        "language": "Solidity",
        "sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
        "settings": {
            "outputSelection": {
                "*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
            }
        },
    },
    solc_version="0.6.0",
)

with open("compiled_code.json", "w") as file:
    json.dump(compiled_sol, file)


# get bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
    "bytecode"
]["object"]


# get ABI
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]

# to …
Run Code Online (Sandbox Code Playgroud)

python ethereum solidity smartcontracts ganache

13
推荐指数
3
解决办法
1万
查看次数

Solidity 中的内部和私有有什么区别?

在 Solidity 中,我们有四种访问类型。其中两个是privateinternal。如果两者都可以在智能合约中使用,但部署后都不可见,有什么区别?

blockchain solidity smartcontracts

12
推荐指数
2
解决办法
8839
查看次数

如何使用 ethers.js 将 ETH 发送到合约函数?

我正在尝试通过元掩码和 ethers.js 从网络应用程序将 ETH 发送到合约函数。到目前为止我已经尝试过:

const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const splitterManager = new ethers.Contract(contract.address, contract.abi, signer);
var overrides = {value: 5}
const result = await splitterManager.newSplitter(addresses, shares, erc20, overrides);
console.log(result);
Run Code Online (Sandbox Code Playgroud)

但我不断收到“错误:未为 ENS 名称配置解析器或地址(参数=“名称”,值=“”,代码= INVALID_ARGUMENT,版本=合同/ 5.2.0)”。

ethereum solidity smartcontracts ethers.js

12
推荐指数
3
解决办法
1万
查看次数

谁是使用松露部署的合同的所有者?

我正在使用testrpc和松露来测试我的合同.

当我输入时truffle migrate,这会将我的合同部署到testrpc网络.

我的问题是,哪个帐户(来自testrpc帐户)已用于部署合同.

换句话说,谁的合同所有者?

先感谢您

solidity smartcontracts truffle

11
推荐指数
1
解决办法
3510
查看次数

警告:源文件中未提供 SPDX 许可证标识符

我创建了一个新的 Solidity 合约。合同已启动并正在运行,但给了我这个警告。

Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
Run Code Online (Sandbox Code Playgroud)

编译时没有错误。

我在https://remix.ethereum.org/ 中使用的编译器版本是 v0.7.5+commit.eb77ed08 语言:Solidity EVM 版本:编译器默认值

每当我按下编译时,它都会给我警告,但部署时没有问题。

我的代码片段:

pragma solidity ^0.7.5;
contract TestContract {
// Some logic
}


Run Code Online (Sandbox Code Playgroud)

blockchain solidity remix

11
推荐指数
1
解决办法
1万
查看次数

Solidity:如何将 bytes32 表示为字符串

这在其他语言中可能很简单,但我不知道如何在 Solidity 中做到这一点。
我有一个bytes32这样的0x05416460deb76d57af601be17e777b93592d8d4d4a4096c57876a91c84f4a712

不想将字节转换为字符串,而是只想将整个内容表示为字符串,例如“0x05416460deb76d57af601be17e777b93592d8d4d4a4096c57876a91c84f4a712”。
在 Solidity 中如何做到这一点?

更新:
为什么我需要这样做:基本上我连接到一个预言机,它在链外执行一些工作,最后将文件上传到 IPFS。我需要从预言机将内容标识符添加到我的合约中。预言机只能bytes32作为响应发送,因此我将其转换为多重哈希,并仅将来自预言机的digestas发送bytes32到合约。
到目前为止一切顺利,我可以在合约中重新创建多重哈希。问题是,在此之后我创建了一个ERC721(NFT)令牌,并且我必须在元数据中存储一些对 IPFS 文件的引用,该元数据只能是格式的string。这就是我现在被困住的地方。

ethereum solidity

11
推荐指数
1
解决办法
2万
查看次数

错误:Truffle 当前使用 solc 0.5.16,但您的一个或多个合约指定“pragma Solidity ^0.8.0”

错误:Truffle 当前使用 solc 0.5.16,但您的一个或多个合约指定 \xe2\x80\x9cpragma Solidity ^0.8.0\xe2\x80\x9d

\n

这是错误的照片 - https://gyazo.com/2f5ea2f50cc1d4ef5eea2f21d0e04fe7

\n

我的所有合约都使用 ^0.8.0 编译指示。我的 truffle-config 也使用与您在此处看到的相同的版本 -https://gyazo.com/1ec8b28ca48902c091004f8659cf678d

\n

请帮忙。非常感谢。

\n

blockchain ethereum solidity smartcontracts truffle

11
推荐指数
1
解决办法
7752
查看次数

从安全帽中的交易收据中获取事件

我有一份ethers与之进行交易的合同:

const randomSVG = new ethers.Contract(RandomSVG.address, RandomSVGContract.interface, signer)
let tx = await randomSVG.create()
Run Code Online (Sandbox Code Playgroud)

我有一个与此交易有关的事件:

function create() public returns (bytes32 requestId) {
        requestId = requestRandomness(keyHash, fee);
        emit requestedRandomSVG(requestId);
    }
Run Code Online (Sandbox Code Playgroud)

但是,我看不到交易收据中的日志。]( https://docs.ethers.io/v5/api/providers/types/#providers-TransactionReceipt )

// This returns undefined
console.log(tx.logs)
Run Code Online (Sandbox Code Playgroud)

javascript solidity ethers.js hardhat

11
推荐指数
1
解决办法
2万
查看次数