web3p / web3.php

A php interface for interacting with the Ethereum blockchain and ecosystem. Native ABI parsing and smart contract interactions.
MIT License
1.16k stars 543 forks source link

Transfer ERC-1155 tokens via webp3 #277

Closed ayadlinbrintha closed 2 years ago

ayadlinbrintha commented 2 years ago

Hi, I am trying to transfer ERC-1555 token from one wallet to another wallet using the following code, $eth->getTransactionCount($from,function($err,$data) use (&$from_addr_nonce){ $from_addr_nonce = gmp_intval($data->value); });

    $from_addr_nonce = Utils::toHex($from_addr_nonce,true);
    $web3 = new Web3($binance_url);
    $eth = $web3->eth;
    $eth->gasPrice(function ($err, $resp) use (&$gasP) {
        if ($err !== null) {
            throw new \Exception($err->getMessage());
        }
         $gasP = $resp;

    });
    $params = [
        'nonce' => $from_addr_nonce,
        'from' => $from,
        'to' => $contractAddress,
        'data' => $data
    ];
  $data = "0x".$contract->getData('transfer',$user_wallet->address,$nftMint->token_id);
     $transaction = new EthTransaction([
         'nonce' => $from_addr_nonce,
        'from' => $from,
        'to' => $contractAddress,
        'gas' =>  $gasP,
        'gasPrice' => sprintf('0x%s', $gasP->toHex()),
        'gasLimit' => sprintf('0x%s', '895D0'),
        'value'     =>"1",
       // 'value' =>$amount,
       'chainId' => $chain_id,
        'data' =>  $data

    ]);

    $signedTx = $transaction->sign($privKey);
    $txId = '';

    // Sending transaction to the blockchain
    $contract->eth->sendRawTransaction(sprintf('0x%s', $signedTx), function ($err, $tx) use (&$txId) {
        if ($err !== null) {

            throw new \Exception($err->getMessage());
        }

        $txId = $tx;
    });
    return response()->json($txId);
   But i got error and i not seen any function for transferring this.
fiveways commented 2 years ago

@ayadlinbrintha did you find the solution ? do you mind updating this issue, we have had similar issues with transferring ERC-1155, many thanks.