-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalchemy.php
More file actions
38 lines (33 loc) · 977 Bytes
/
alchemy.php
File metadata and controls
38 lines (33 loc) · 977 Bytes
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
<?php
require 'vendor/autoload.php';
use Web3\Web3;
$apiKey = 'MkCoC6RmzJXTJryxG7iFXvRvX9zIr4aA';
$endpoint = 'https://polygon-mainnet.g.alchemy.com/v2/' . $apiKey;
$contractAddress = '0xf6fe664d0D61297fBfBb829A1FF77286b887a9Fd';
// Inicializar Web3
$web3 = new Web3($endpoint);
// La ABI del contrato (simplificada para este ejemplo)
$contractAbi = [
[
'constant' => true,
'inputs' => [],
'name' => 'baseURI',
'outputs' => [
['name' => '', 'type' => 'string']
],
'payable' => false,
'stateMutability' => 'view',
'type' => 'function',
]
];
$contract = new \Web3\Contract($contractAbi, $contractAddress, $web3->provider);
// Obtener baseURI
$contract->call('baseURI', [], function ($err, $result) use (&$baseURI) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
$baseURI = $result[0];
echo 'El valor de baseURI es: ' . $baseURI;
});
?>