Skip to content

Convert ether.js USDT Script to web3.php? #360

@skykingisepic

Description

@skykingisepic

First - sorry for my noobness, with a little initial guidance I should be able to wrap my head around this quickly.

I'm trying to automate sending Membership Commissions pending to each member's USDT Wallet from the Commissions USDT Wallet. globals: $usdtradd, $privkey, and $pendamt for a function that returns $txhash. Will hard code USDT Send Address and contract address. The more I search for examples, the more random results I get, each completely different than the last so I'm getting confused and frustrated. And help or advice greatly appreciated.

I came across web3 snippet to send USDT and was hoping to convert it to php:

var { Web3 } = require("web3");
var provider = "https://mainnet.infura.io/v3/YOUR-API-KEY";
var web3Provider = new Web3.providers.HttpProvider(provider);
var web3 = new Web3(web3Provider);

const USDTAddress = "0xAB0874D3e7Cd256Cd3F1A9480c3b0C01109E2117"; //sender contract address?

// 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"},
];

web3.eth.accounts.wallet.add(SENDER_PRIVATE_KEY); //$pkey

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

const to = "0x123"; //$usdtaddr
const amount = "1000000"; // $amt: send 1 USDT - don't forget to account for the decimals - 6 for USDT

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

} //SENDER_ADDRESS is USDT_ADDRESS (contract address)? Not clear on this value needed here

run();

//end

This is what I have so far for php (not much but struggling to convert the web3.js script)

use Web3\Web3;
use Web3\Providers\HttpProvider;
use Web3\Contract;

function sendUSDT() {
global $pkey, $usdtadd, $commpend;
$web3 = new Web3(new HttpProvider('https://mainnet.infura.io/v3/API_KEY'));
$eth = $web3->eth;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions