- web3
- web3.version.api
- web3.version.node
- web3.version.network
- web3.version.ethereum
- web3.version.whisper
- web3.isConnected
- web3.setProvider
- web3.currentProvider
- web3.reset
- web3.sha3
- web3.toHex
- web3.toAscii
- web3.fromAscii
- web3.toDecimal
- web3.fromDecimal
- web3.fromWei
- web3.toWei
- web3.toBigNumber
- web3.net.listening
- web3.net.peerCount
- web3.eth
- web3.eth.defaultAccount
- web3.eth.defaultBlock
- web3.eth.syncing
- web3.eth.isSyncing
- web3.eth.coinbase
- web3.eth.mining
- web3.eth.hashrate
- web3.eth.gasPrice
- web3.eth.accounts
- web3.eth.blockNumber
- web3.eth.register
- web3.eth.unRegister
- web3.eth.getBalance
- web3.eth.getStorageAt
- web3.eth.getCode
- web3.eth.getBlock
- web3.eth.getBlockTransactionCount
- web3.eth.getUncle
- web3.eth.getTransaction
- web3.eth.getTransactionFromBlock
- web3.eth.getTransactionReceipt
- web3.eth.getTransactionCount
- web3.eth.sendTransaction
- web3.eth.sendRawTransaction
- web3.eth.sign
- web3.eth.call
- web3.eth.estimateGas
- web3.eth.filter
- web3.eth.contract
- web3.eth.getCompilers
- web3.eth.compile.solidity
- web3.eth.compile.lll
- web3.eth.compile.serpent
- web3.eth.namereg
- web3.db.putString
- web3.db.getString
- web3.db.putHex
- web3.db.getHex
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
web3.toHex
web3.toHex
将任何值转为HEX
。
参数:
String|Number|Object|Array|BigNumber
- 需要转化为HEX
的值。如果是一个对象或数组类型,将会先用JSON.stringify
1进行转换成字符串。如果传入的是BigNumber
2,则将得到对应的Number
的HEX
。
示例:
//初始化基本对象
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
var BigNumber = require('bignumber.js');
var str = "abcABC";
var obj = {abc: 'ABC'};
var bignumber = new BigNumber('12345678901234567890');
var hstr = web3.toHex(str);
var hobj = web3.toHex(obj);
var hbg = web3.toHex(bignumber);
console.log("Hex of Sring:" + hstr);
console.log("Hex of Object:" + hobj);
console.log("Hex of BigNumber:" + hbg);
$ node test.js
Hex of Sring:0x616263414243
Hex of Object:0x7b22616263223a22414243227d
Hex of BigNumber:0xab54a98ceb1f0ad2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论