简体   繁体   English

JS 常量在 ethers.js 的另一个常量中

[英]JS constant inside another constant with ethers.js

I'm using ethers.js to encode in ABI a IPFS hash provided by a text box on an html page, in order to save it on the blockchain.我正在使用 ethers.js 在 ABI 中编码由 html 页面上的文本框提供的 IPFS hash,以便将其保存在区块链上。 To do that, I have an input id'd as "ipfs-hash", called with a variable.为此,我有一个输入 id 为“ipfs-hash”,用一个变量调用。 An then, another variable which encodes it.然后,另一个对其进行编码的变量。 Nevertheless, this last step doen't work, and when I try to take the hash from a variable the code breaks.尽管如此,这最后一步不起作用,当我尝试从变量中获取 hash 时,代码会中断。 However, the second variable seems to work fine when I change但是,当我更改时,第二个变量似乎工作正常

INPUTHASH

variable for an actual value.变量为实际值。

'Qm...'
const INPUTHASH =  $('#ipfs-hash').html //Direct input from text box                
const ABIOUTPUT = ethers.utils.defaultAbiCoder.encode([ 'string' ], [ INPUTHASH ] );

Solved.解决了。 It was a problem with Jquery,js.这是 Jquery,js 的问题。 not ethers.js.不是 ethers.js。

const INPUTHASH = $('#ipfs-hash').val();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM