This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
/
callPolygonSmartContractMethod.php
77 lines (61 loc) · 2.24 KB
/
callPolygonSmartContractMethod.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Copyright (c) 2022-2023 tatum.io
*
* @link https://tatumio.github.io/tatum-php/Api/PolygonApi/#callpolygonsmartcontractmethod
* @license MIT
* @author Mark Jivko
*
* SECURITY WARNING
* Execute this file in CLI mode only!
*/
"cli" !== php_sapi_name() && exit();
// Use any PSR-4 autoloader
require_once dirname(__DIR__, 3) . "/autoload.php";
// Set your API Keys 👇 here
$sdk = new \Tatum\Sdk();
// 🐛 Enable debugging on the MainNet
$sdk->mainnet()->config()->setDebug(true);
$arg_call_polygon_smart_contract_method = (new \Tatum\Model\CallPolygonSmartContractMethod())
// The address of the smart contract
->setContractAddress('0xC9c8ba8C7e2EAF43e84330Db08915A8106d7bD74')
// (optional) Amount of the assets to be sent.
->setAmount('100000')
// Name of the method to invoke on smart contract.
->setMethodName('transfer')
// ABI of the method to invoke.
->setMethodAbi(
json_decode(
'{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"}'
)
)
// string[]
->setParams(["0x632"])
// Private key of sender address. Private key, or signature Id must be present.
->setFromPrivateKey('0x05e150c73f1920ec14caa1e0b6aa09940899678051a78542840c2668ce5080c2')
// (optional) Nonce to be set to Polygon transaction. If not present, last known nonce will be used.
->setNonce(null)
// (optional) \Tatum\Model\CustomFee
->setFee(null);
try {
/**
* POST /v3/polygon/smartcontract
*
* @var \Tatum\Model\CallSmartContractMethod200Response $response
*/
$response = $sdk->mainnet()
->api()
->polygon()
->callPolygonSmartContractMethod($arg_call_polygon_smart_contract_method);
var_dump($response);
} catch (\Tatum\Sdk\ApiException $apiExc) {
echo sprintf(
"API Exception when calling api()->polygon()->callPolygonSmartContractMethod(): %s\n",
var_export($apiExc->getResponseObject(), true)
);
} catch (\Exception $exc) {
echo sprintf(
"Exception when calling api()->polygon()->callPolygonSmartContractMethod(): %s\n",
$exc->getMessage()
);
}