我如何连接字符串的可靠性?
var str = 'asdf'
var b = str + 'sdf'
Run Code Online (Sandbox Code Playgroud)
似乎不起作用..
我查阅了文档(https://github.com/ethereum/wiki/wiki/Solidity-Tutorial#elementary-types-value-types),并没有提到有关字符串连接的内容.但据说它适用于点('.')?
"[...] a mapping key k is located at sha3(k . p) where . is concatenation."
Run Code Online (Sandbox Code Playgroud)
也没为我工作..:/
我从事 Hardhat 项目已经有一段时间了。
一段时间后,当我运行
npx hardhat node
启动 HH 服务器时,出现以下错误:

我尝试研究该错误并在安全帽网站上找到了这个
HH12: Hardhat is not installed or installed globally
You tried to run Hardhat from a global installation or not installing it at all. This is not supported.
Please install Hardhat locally using npm or Yarn, and try again.
Run Code Online (Sandbox Code Playgroud)
有趣的是,我创建了一个新的 HH 项目并重新安装了所有内容
,然后将我的代码导入到新项目中,这似乎解决了问题......
但过了一段时间,问题又开始了。
我不能每次发生这种情况时都创建一个新项目。
我已经被困了好几天了,非常感谢任何帮助。
操作系统:windows10
我的 dApp 必须连接到 MetaMask。文档中有两种粗鲁的解决方案:让用户每次手动单击连接 btn 或在页面加载后弹出连接确认。我想实现唯一方便的解决方案:第一次用户通过单击连接 btn 并与 MetaMask 弹出窗口交互来手动连接,然后我的 dApp 检测到连接仍然建立并使用此连接。我找不到解决方案,但我在其他 dApp 中看到了这个(例如捕获以太)我使用:
import detectEthereumProvider from '@metamask/detect-provider';
const provider = await detectEthereumProvider();
if (provider) {
connect(provider)
} else {
// kind of "Install the MetaMask please!"
}
function connect(provider) {
// How to check if the connection is here
if (//connection established) {
// Show the user connected account address
} else {
// Connect
provider.request({ method: "eth_requestAccounts" })
.then // some logic
}
}
Run Code Online (Sandbox Code Playgroud) 我想制作一个简单的智能合约,它有一个列表,可以设置项目,并可以获取列表.
代码实力:
contract lister {
mapping(int => string) list;
int id = 0;
function getList() returns ( /*HERE*/ ) {
return list;
}
function setItemToList(string str) {
list[id] = str;
id++;
}
}
Run Code Online (Sandbox Code Playgroud)
我想让getList()返回列表,但返回类型不兼容.我怎样才能做到这一点?
当我想测试字符串值是否正确时,会出现问题.数字被正确断言,并且在尝试编译时不会返回错误消息.但是,当我尝试断言一个字符串时,它返回以下错误消息:
Error: Member "equal" is not available in type(library Assert) outside of storage.
Assert.equal(token.symbol(), "$", "The symbol of the token should be $");
^----------^
Compiliation failed. See above.
Run Code Online (Sandbox Code Playgroud)
Token.sol
pragma solidity ^0.4.8;
contract Token {
/* The amount of tokens a person will get for 1 ETH */
uint256 public exchangeRate;
/* The name of the token */
string public name;
/* The address which controls the token */
address public owner;
/* The symbol of the token */
string …Run Code Online (Sandbox Code Playgroud) 我试着去整合web3js与Trezor在松露开发网络或使用设有通往Ropsten测试网络.
我们的想法是使用硬件钱包签署交易,然后使用web3js发送原始交易
我得到了我们没有平衡来进行交易,可能是因为web3js没有使用10个松露帐户中的一个并使用不在我的本地网络中的trezor地址.
在ropsten我有一些醚,我得到"无效地址"
有没有办法使用web3js将已签名的交易(使用trezor)发送到松露开发网络?我的意思是,有没有办法将trezor地址包含在松露网络中?
松露的情况在这里有更详细的解释,但问题可以概括为" 有没有办法将硬件钱包纳入松露开发网络? ":https://github.com/trufflesuite/truffle/issues/973
使用ropsten我已经设法发送一个事务并在回调中接收一个事务哈希,但如果我们查询该事务,我们得到该事务不存在..所以..这怎么可能?
我也尝试将合同部署到Ropsten,现在我在调用智能合约函数时得到"无效地址".也许签名功能错了?有人可以将Trezor交易登录与web3js集成吗?
你们看到我们遵循的签名和发送过程中有什么问题吗?也许R,V和S参数处理有问题..
另一个重要的事情是我使用https://github.com/ethereumjs/ethereumjs-tx来创建原始事务
web3js,truffle和trezzor中发布的问题可以提供更多信息:
亲切的问候
trezorLogin = async()=> {
let trezor= await this.getTrezor();
// site icon, optional. at least 48x48px
let hosticon = 'https://doc.satoshilabs.com/trezor-apps/_images/copay_logo.png';
// server-side generated and randomized challenges
let challenge_hidden = '';
let challenge_visual = '';
//use anonimous functions on callback otherwise returns cross origin errors …Run Code Online (Sandbox Code Playgroud) 我试图将我简单的可靠性智能合约部署到Rinkeby网络上,但我一直收到错误:
UnhandledPromiseRejectionWarning:错误:无法存储合同代码,请检查您的气体限制.
我的可靠性代码很简单
pragma solidity ^0.4.18;
contract Greetings{
string public message;
function Greetings(string initialMessage) public{
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
Run Code Online (Sandbox Code Playgroud)
我的部署脚本是:
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface,bytecode} = require('./compile');
const provider = new HDWalletProvider(
'twelve word mnemonic...',
'https://rinkeby.infura.io/GLm6McXWuaih4gqq8nTY'
);
const web3 = new Web3(provider);
const deploy = async () => {
accounts = await web3.eth.getAccounts();
console.log('attempting to deploy from account',accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface)) …Run Code Online (Sandbox Code Playgroud) 我在 remix 中尝试了像上面那样的 Solidity 示例,solidity 版本 > 0.5.0 但我现在收到此错误。解决此错误的方法是什么?
contract MyContract {
string value;
function get() public view returns (string) {
return value;
}
function set(string _value) public {
value = _value;
}
constructor() public {
value = "myValue";
}
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个以太坊DApp.DApp由具有关联数据的用户组成,例如电子邮件,姓名和个人资料图片.我想将用户的内容作为JSON对象存储在IPFS中,并使用IPFS哈希在链上引用它.我怎样才能将这些数据与特定用户相关联?从某种意义上说,后续与DApp的交互将用户与存储在IPFS中的数据联系起来.这是使用用户帐户哈希和某种密码完成的吗?
例如,用户A有兴趣使用DApp,因此,提供他或她的电子邮件,姓名和个人资料图片.然后,任何与DApp的后续交互,如评论或帖子,都会将此用户链接到IPFS中的相应用户数据.
对这种建模用户的方式的任何建议或调整将不胜感激.谢谢!
(PS我来自传统的网络/移动应用程序世界,所以我只是习惯于使用智能合约对事物进行建模.所以如果这是一个简单或结构不合理的问题,我会提前道歉.)