我有一份合同A和一份合同B。
合约A声明了这个函数:
function getIntValue() constant returns (uint);
Run Code Online (Sandbox Code Playgroud)
delegatecall从 B承包 A 的功能的适当汇编代码是什么getIntValue?我对组装还不太有经验,所以到目前为止我只有这个不起作用:
function getContractAIntValue() constant returns (uint c) {
address addr = address(contractA); // contract A is stored in B.
bytes4 sig = bytes4(sha3("getIntValue()")); // function signature
assembly {
let x := mload(0x40) // find empty storage location using "free memory pointer"
mstore(x,sig) // attach function signature
let status := delegatecall(sub(gas, 10000), addr, add(x, 0x04), 0, x, 0x20)
jumpi(invalidJumpLabel, iszero(status)) // error out if unsuccessful delegatecall
c := …Run Code Online (Sandbox Code Playgroud) 我正在构建一个合约,要求新用户发送 0.1 以太币才能进入投资回合。
我已经为此苦苦挣扎了一段时间,我不知道如何在合约中存储新投资者的地址,以便稍后可以使用“地址索引”。
据我所知,不建议使用动态数组,因为它们很容易使用“太多gas”并导致合约永远陷入困境。
我认为可以完成一个简单的测试,但我不确定如何做。
这是我正在使用的代码。它基于 Rob Hitchens 撰写的精彩文章。
address[] userIndex; // New user address gets stored in dynamic array
function invest() public payable {
require(msg.value == 0.1 ether); // checks if new investor sent 0.1 ether
userIndex.push(msg.sender); // adds new user to userIndex
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Solidity 项目,其中我将字符串编码为 SHA256 哈希值,现在我想解码 SHA256 哈希值并检索实际数据。请帮助锄头做这件事。
下面是我用来散列字符串的代码。
pragma solidity ^0.4.26;
contract TestShaAlgo {
function getSha256(string str) public view returns (bytes32) {
bytes32 hash = sha256(abi.encodePacked(str));
return hash;
}
}
Run Code Online (Sandbox Code Playgroud) 我想在我的本地网络上部署智能合约。我通过执行本地节点
PRIVATE_CONFIG=ignore nohup geth --datadir ./Node1/new-
node-1
--nodiscover --verbosity 5 --networkid 31337 --raft --
raftport 51001 --rpc --rpcaddr 0.0.0.0 --rpcport 22101 --
rpcapi
admin,db,eth,debug,miner,net,shh,txpool,personal,web3,
quorum,raft --emitcheckpoints --port 21101 2>>node1.log &
Run Code Online (Sandbox Code Playgroud)
我必须使用 localhost:\127.0.0.1:21101 或 22101?我想知道这两个端口之间的区别以及用途?
如果您不介意的话,还有一个问题:当我使用端口 21101 时,它无法连接,当我查阅节点日志时,我发现:
Failed RLPx handshake addr=[::1]:42552 conn=inbound
err="read tcp [::1]:21102->[::1]:42552: i/o timeout"
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用注入令牌 web3.ts 设置我的 web3 提供程序,该令牌由 app.component.ts 导入并用于 async ngOnInit() 中。
我已经尝试过了: https://medium.com/coinmonks/https-medium-com-alexanddanik-ethereum-dapp-with-angular-angular-material-and-ngrx-f2c91435871b 它向我显示了同样的错误。我也尝试过: https: //www.udemy.com/course/blockchain-ninja-develop-ethereum-dapp-with-angular/ 当然,它向我显示了同样的错误。
web3.ts:
import { InjectionToken } from '@angular/core';
import Web3 from 'web3';
export const WEB3 = new InjectionToken<Web3>('web3', {
providedIn: 'root',
factory: () => {
try {
const provider = ('ethereum' in window) ? window['ethereum'] : Web3.givenProvider;
return new Web3(provider);
} catch (err) {
throw new Error('Non-Ethereum browser detected. You should consider trying Mist or MetaMask!');
}
}
});
Run Code Online (Sandbox Code Playgroud)
应用程序组件.ts:
import { WEB3 } from …Run Code Online (Sandbox Code Playgroud) 我想在我的合约中包含一个内部方法,该方法允许在由参数命名的存储中创建一个新的 uint256。就像是:
function createUint (string memory _name) internal {
/*
* creates a new uint256 named _name in storage
*/
}
Run Code Online (Sandbox Code Playgroud)
我的猜测是它需要内联汇编,但我不知道如何
我需要将字符串转换0x2fe84e3113d7b为浮点类型。该字符串来自infura.io API作为帐户余额。我尝试使用https://github.com/mbezzanov/ethereum-converter,但在这种情况下没有任何意义(它总是以任何方式返回 0.00000 )。如何0.000842796652117371用php将此字符串转换为?
use Bezhanov\Ethereum\Converter;
...
$this->converter = new Converter();
$weiValue = '0x1e1e83d93bb6ebb88bbaf';
dump($this->converter->fromWei($weiValue)); // returns 0.00000000000000000000000000000000000
$hexValue = hexdec($weiValue); // returns 2.2757423599815E+24
dump($this->converter->fromWei($hexValue)); // returns the same
Run Code Online (Sandbox Code Playgroud)
我猜这是由于值太长造成的$hexValue(我的意思是转换器无法转换长整数)。但是如何从这个十六进制中获取以太值呢?
有geth程序在运行,并提供--rpc服务。
服务做什么:
mysql)。目前我们正在使用full模式,但它有点慢,并且需要更多的磁盘空间。
fast模式是否足以满足上述用途?fullmdoe切换到fastmode,会geth不会要重新下载所有年的历史?或者,它会重用历史?(我在Ethereum现场问了另一个关于以太坊的问题,有兴趣的也可以看看:https : //ethereum.stackexchange.com/questions/78293/how-to-migrate-geths-data )
我目前正在 Hyperledger 中开展一个项目,我想通过在网络节点上分发文档文件并将文档文件取回,将 pdf 和 docs 等文件上传到 hyperledger 区块链中。请帮助我如何做以及我应该如何批准。如果在 Hyperledger 中无法实现,请告诉我可以通过哪个区块链实现。提前致谢。
blockchain ethereum smartcontracts hyperledger hyperledger-fabric
我的 solc 版本:
"solc": "^0.7.1",
Run Code Online (Sandbox Code Playgroud)
当我尝试构造包含映射的结构时,出现此错误:“无法构造包含(嵌套)映射的结构”
这是我的可靠性代码。
活动.sol
contract Campaign {
struct Request {
...
// I guess this might cause an error
mapping(address => bool) approvals;
}
constructor(uint256 minimum, address creator) {
...
}
function createRequest(
string memory description,
uint256 value,
address payable recipient
) public onlyManager {
Request memory newRequest = Request({
// Here the compiler complains
});
}
...
Run Code Online (Sandbox Code Playgroud)
如果我想将映射放入请求结构中,还有其他方法吗?谢谢
ethereum ×10
solidity ×6
blockchain ×4
geth ×2
angular ×1
compilation ×1
evm ×1
go-ethereum ×1
hyperledger ×1
php ×1
quorum ×1
sha256 ×1
typescript ×1