PHP code example of amashukov / abi-encoder-php

1. Go to this page and download the library: Download amashukov/abi-encoder-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

amashukov / abi-encoder-php example snippets


use Amashukov\AbiEncoder\AbiEncoder;

AbiEncoder::methodId('withdraw(address,uint256)');   // 'f3fef3a3'

$calldata = AbiEncoder::encodeCall('withdraw(address,uint256)', [
    ['address', '0x1234567890123456789012345678901234567890'],
    ['uint256', '500000000000000000'],   // decimal string; bigints supported via ext-gmp
]);
// 0xf3fef3a3000000…0006f05b59d3b20000

AbiEncoder::encodeAddress('0xABCDEF…');         // left-padded to 32 bytes, lowercased
AbiEncoder::encodeUint('0xFF');                 // accepts hex or decimal; bigint-safe
AbiEncoder::encodeUint('115792089237316195423570985008687907853269984665640564039457584007913129639935'); // max uint256
AbiEncoder::encodeBytes('0xdeadbeef');          // length word + right-padded data
AbiEncoder::encodeBytes('v1', isString: true);  // UTF-8 string as dynamic bytes
bash
composer