【问题标题】:Token real synchronization from my website令牌从我的网站真正同步
【发布时间】:2019-07-31 05:54:57
【问题描述】:

我喜欢在我的网站中集成一个真正的代币同步(从分销商钱包帐户到用户的钱包地址,代币需要转移)。我的网站需要与区块链交互 真实token需要转入用户的钱包地址

如果有体验过真币同步的尽快告诉我们

【问题讨论】:

    标签: synchronization token ethereum solidity ico


    【解决方案1】:

    您可以使用 Web3 库创建 node.js API。 https://web3js.readthedocs.io/en/1.0/

    如果您想向用户发送代币,您必须发送原始交易并在 rawTx 数据中使用合约方法 transfer(),伪代码示例:

        let rawTx = {
            nonce: web3.utils.toHex(count),
            gasPrice: web3.utils.toHex(gasPrice),
            gasLimit: '0x2fefd8',
            to: tokenAddress,
            value: '0x00',
            data: contract.methods.transfer(toAddress, tokens).encodeABI(),
            chainId: '0x01'
        };
    
    
        web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')).then(
            data => {
                console.log(`Tokens transfered to ${toAddress} on ${amount} TOKENS`);
            }
        );
    

    如果你已经发送了代币,你可以通过 balanceOf() 查询用户钱包的代币余额

    contract.methods.balanceOf(address)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      • 2017-11-10
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2015-10-15
      相关资源
      最近更新 更多