首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使USDT发送事务自动化?

如何使USDT发送事务自动化?
EN

Stack Overflow用户
提问于 2022-06-29 11:46:41
回答 1查看 373关注 0票数 -1

我想在我的网站上做效用,这样那些不喜欢产品的人就可以在我们的网站上拿回他们的钱。通过单击submit按钮,我希望将usdt (TRC或ERC)发回给客户。甚至有可能。我觉得有可能是索拉娜区块链。例如,幻影钱包中有自动批准。但我需要在USDT

客户将以邮寄方式输入他的地址,并自动将usdt发送给他。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-29 12:56:39

您可以将发送方地址的私钥传递给web3.js或任何其他包装器(以太 for JS,web3.php for PHP,.)以太节点的JSON。您可以运行自己的节点,但更常见的情况是使用第三方节点提供程序(如恩弗拉 )。

web3.js实例构建事务,使用私钥对其进行签名,并将其发送到该节点以广播到网络的其余部分(Ethereum、Tron或其他取决于连接到哪个网络的节点)。

使用web3js的示例:

代码语言:javascript
复制
const Web3 = require("web3");
const web3 = new Web3(NODE_URL);

const USDTAddress = "0xdAC17F958D2ee523a2206206994597C13D831ec7";

// just the `transfer()` function is sufficient in this case
const ERC20_ABI = [
    {"constant":true,"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},
    
];

// you're passing the private key just to the local web3js instance
// it's not broadcasted to the node
web3.eth.accounts.wallet.add(PRIVATE_KEY_OF_SENDER_ADDRESS);

async function run() {
    const tokenContract = new Web3.eth.Contract(USDTAddress, ERC20_ABI);

    const to = "0x123";
    const amount = "1000000"; // don't forget to account for the decimals

    // invoking the `transfer()` function of the contract
    const transaction = await tokenContract.methods.transfer(to, amount).send({from: SENDER_ADDRESS});
}

run();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72800889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档