@@ -14,6 +14,8 @@ class ImmutableXClient
1414{
1515 private HttpClientInterface $ httpClient ;
1616
17+ private string $ env = 'prod ' ;
18+
1719 public function __construct (
1820 private readonly string $ publicKey ,
1921 private readonly string $ privateKey ,
@@ -22,9 +24,14 @@ public function __construct(
2224 $ this ->httpClient = HttpClient::create ();
2325 }
2426
27+ public function setEnv (string $ env ): void
28+ {
29+ $ this ->env = $ env ;
30+ }
31+
2532 public function transferNft (array $ payload ): array
2633 {
27- $ response = $ this ->httpClient ->request ('POST ' , ' https://api.x.immutable.com /v1/signable-transfer-details ' , [
34+ $ response = $ this ->httpClient ->request ('POST ' , $ this -> getIMXEndpoint () . ' /v1/signable-transfer-details ' , [
2835 'json ' => [
2936 'amount ' => '1 ' ,
3037 'receiver ' => $ payload ['recipient ' ],
@@ -55,7 +62,7 @@ public function transferToken(array $payload): array
5562 $ tokenData ['token_address ' ] = TokenHelper::getTokenContract ($ payload ['token ' ]['token_type ' ]);
5663 }
5764
58- $ response = $ this ->httpClient ->request ('POST ' , ' https://api.x.immutable.com /v1/signable-transfer-details ' , [
65+ $ response = $ this ->httpClient ->request ('POST ' , $ this -> getIMXEndpoint () . ' /v1/signable-transfer-details ' , [
5966 'json ' => [
6067 'amount ' => $ payload ['token ' ]['quantity ' ],
6168 'receiver ' => $ payload ['recipient ' ],
@@ -80,7 +87,7 @@ private function transfer(array $resultSignable): array
8087 $ starkNetSigner = new StarkSigner ($ this ->publicKey , $ this ->privateKey );
8188 $ starkSignature = $ starkNetSigner ->signMessage ($ resultSignable ['payload_hash ' ]);
8289
83- $ response = $ this ->httpClient ->request ('POST ' , ' https://api.x.immutable.com /v1/transfers ' , [
90+ $ response = $ this ->httpClient ->request ('POST ' , $ this -> getIMXEndpoint () . ' /v1/transfers ' , [
8491 'headers ' => [
8592 'x-imx-eth-address ' => $ this ->publicKey ,
8693 'x-imx-eth-signature ' => $ ethereumSignature ,
@@ -100,4 +107,9 @@ private function transfer(array $resultSignable): array
100107
101108 return $ response ->toArray ();
102109 }
110+
111+ private function getIMXEndpoint (): string
112+ {
113+ return $ this ->env === 'dev ' ? 'https://api.ropsten.x.immutable.com ' : 'https://api.x.immutable.com ' ;
114+ }
103115}
0 commit comments