15 使用web3在heco上进行ht转账应该如何操作

请问使用web3在heco上进行ht转账应该如何操作 能给出代码吗?

请先 登录 后评论

最佳答案 2021-07-25 10:48

基本是 初始化 web3时,使用 heco 节点作为 provider 即可。 如果是调用钱包转账,你选择好对应的 heco 网络,其他就和以太坊一样。

即:

// 用节点
var web3 = new Web3(Web3.providers.HttpProvider("https://http-mainnet.hecochain.com");
// 用当前钱包
var web3 = new Web3(window.ethereum)

发起交易就和以太坊完全一样了:

// 使用 promise
web3.eth.sendTransaction({
from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe',
to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
value: '1000000000000000'
})
.then(function(receipt){
...
});

参考文档: web3.eth — web3.js 中文文档

请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 0 收藏,2598 浏览
  • carvin 提出于 2021-07-25 09:07

相似问题