File tree Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace ArkEcosystem \Client \API ;
6
+
7
+ class EVM extends AbstractAPI
8
+ {
9
+ /**
10
+ * Make an eth_call POST request to retrieve data from a contract.
11
+ *
12
+ * @param array $payload
13
+ *
14
+ * @return array|null
15
+ */
16
+ public function ethCall (array $ payload ): ?array
17
+ {
18
+ $ body = [
19
+ 'jsonrpc ' => '2.0 ' ,
20
+ 'method ' => 'eth_call ' ,
21
+ 'params ' => [$ payload , 'latest ' ],
22
+ 'id ' => null ,
23
+ ];
24
+
25
+ $ headers = [
26
+ 'Content-Type ' => 'application/json ' ,
27
+ ];
28
+
29
+ return $ this ->withApi ('evm ' )->post ('api/ ' , $ body , $ headers );
30
+ }
31
+ }
Original file line number Diff line number Diff line change @@ -128,7 +128,8 @@ public function getHosts(): array
128
128
*/
129
129
public function api (string $ name ): API \AbstractAPI
130
130
{
131
- $ name = ucfirst ($ name );
131
+ $ name = $ name === 'evm ' ? 'EVM ' : ucfirst ($ name );
132
+
132
133
$ class = "ArkEcosystem \\Client \\API \\{$ name }" ;
133
134
134
135
if (! class_exists ($ class )) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace ArkEcosystem \Tests \Client \API ;
6
+
7
+ use ArkEcosystem \Tests \Client \TestCase ;
8
+
9
+ /**
10
+ * @covers \ArkEcosystem\Client\API\EVM
11
+ */
12
+ class EVMTest extends TestCase
13
+ {
14
+ /** @test */
15
+ public function eth_call_calls_correct_url ()
16
+ {
17
+ $ this ->assertResponse (
18
+ method: 'POST ' ,
19
+ path: 'api/ ' ,
20
+ callback: function ($ client ) {
21
+ return $ client ->evm ()->ethCall ([
22
+ 'from ' => '0x1234567890abcdef ' ,
23
+ 'to ' => '0xfedcba0987654321 ' ,
24
+ 'data ' => '0xabcdef ' ,
25
+ ]);
26
+ },
27
+ expectedApi: 'evm '
28
+ );
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments