PHP code example of skopa / ethereum-rpc-wallet

1. Go to this page and download the library: Download skopa/ethereum-rpc-wallet 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/ */

    

skopa / ethereum-rpc-wallet example snippets


use \Skopa\EthereumWallet\Contracts\ERC20TokenContract;

class ExampleContract extends ERC20TokenContract
{
    public function getAddress(): string
    {
        return 'Contract address here';
    }
    
    public function getABIJson(): ?string
    {
        return file_get_contents('ABI.json');
    }

    public function getDecimals(): int
    {
        return 18;
    }
}

$exampleContract = new ExampleToken();

$networkClient = new JsonRpcNetworkClient(
    'http://localhost:8545', 
    '90'
);

$wallet = \Skopa\EthereumWallet\Wallet::fromPublicAddress(
    $network,
    'Address in format: 0x...'
);

$wallet->unlock('private key');

$wallet = \Skopa\EthereumWallet\Wallet::fromPrivateKey(
    $network,
    'private key'
);

$contractManager = $wallet->contract($exampleContract);

class ExampleContract extends Contract
{
    public function myMethod(string $uint)
    {
        return '0x'
            . $this->functionSha('myMethod')
            . $this->formattedArg($amount);
    }
}

$contract = new ExampleContract;

$contractManager = $wallet->customContract($contract);

$custom = $contractManager->callDirectly(function (ExampleContract $token) {
    return $token->mint(\Skopa\EthereumWallet\Utils::amountToDecimalHex(
        \Brick\Math\BigDecimal::of('10')
    ));
});

class ExampleContract extends ERC20TokenContract
{
    public function getAddress(): string
    {
        // ...
    }

    public function getABIJson(): ?string
    {
        // ...
    }

    public function getDecimals(): int
    {
        // ...
    }
    
    public function mint(string $amount)
    {
        return '0x'
            . $this->functionSha('mint')
            . $this->formattedArg($amount);
    }
}

$custom = $contractManager->callDirectlySigned(function (ExampleContract $token) {
    return $token->mint(\Skopa\EthereumWallet\Utils::amountToDecimalHex(
        \Brick\Math\BigDecimal::of('10'), $token->getDecimals()
    ));
});

$transaction = new \Skopa\EthereumWallet\Transaction('recipient address', '2.4')

$res = $contractManager->transfer($transaction);

$receipt = $wallet->receipt('transaction hash');