@@ -37,16 +37,22 @@ function thirdweb_contract_read( $atts = [], $content = null, $tag = '') {
3737 array (
3838 'address ' => get_option ('global_contract_address ' , '0x26959366660AC1273C446bc884B3059fAeF5fD94 ' ),
3939 'chain ' => get_option ('global_contract_chain ' , '84531 ' ),
40- 'function ' => 'name ' ,
40+ 'function ' => 'tokenURI:0 ' ,
4141 ), $ atts , $ tag
4242 );
4343
44+ // Split function attribute into function name and arguments
45+ $ function_parts = explode (': ' , $ twcontractread_atts ['function ' ]);
46+ $ function_name = $ function_parts [0 ];
47+ $ function_args = isset ($ function_parts [1 ]) ? explode (', ' , $ function_parts [1 ]) : array ();
48+
4449 // Call the REST API
4550 $ engine_api_endpoint = get_option ('engine_api_endpoint ' );
4651 if (empty ($ engine_api_endpoint )) {
4752 return '<span style="color:red;">Error: No engine API endpoint found. Please set the engine API endpoint in the plugin settings.</span> ' ;
4853 }
49- $ url = $ engine_api_endpoint . '/contract/ ' . $ twcontractread_atts ['chain ' ] . '/ ' . $ twcontractread_atts ['address ' ] . '/read?functionName= ' . $ twcontractread_atts ['function ' ];
54+ // Build endpoint URL with function name and arguments
55+ $ url = $ engine_api_endpoint . '/contract/ ' . $ twcontractread_atts ['chain ' ] . '/ ' . $ twcontractread_atts ['address ' ] . '/read?functionName= ' . $ function_name . '&args= ' . implode (', ' , $ function_args );
5056
5157 $ engine_access_token = get_option ('engine_access_token ' );
5258 if (empty ($ engine_access_token )) {
@@ -57,7 +63,6 @@ function thirdweb_contract_read( $atts = [], $content = null, $tag = '') {
5763 'Authorization ' => 'Bearer ' . $ engine_access_token ,
5864 'Content-Type ' => 'application/json '
5965 )
60-
6166 );
6267
6368 $ response = wp_remote_get ( $ url , $ args );
@@ -70,7 +75,11 @@ function thirdweb_contract_read( $atts = [], $content = null, $tag = '') {
7075 if ( is_array ( $ response ) && ! is_wp_error ( $ response ) ) {
7176 $ body = $ response ['body ' ];
7277 $ data = json_decode ( $ body );
73- $ result = '<span> ' . esc_html ( $ data ->result ) . '</span> ' ;
78+ if (isset ($ data ->result )) {
79+ $ result = '<span> ' . esc_html ( $ data ->result ) . '</span> ' ;
80+ } else {
81+ $ result = '<span style="color:red;">Error: No result found in the response.</span> ' ;
82+ }
7483 }
7584
7685 }
@@ -127,6 +136,7 @@ function thirdweb_wp_options() {
127136 <td><input type="text" name="global_contract_chain" placeholder="84531" value="<?php echo esc_attr (get_option ('global_contract_chain ' )); ?> "/></td>
128137 </tr>
129138 </table>
139+
130140 <?php submit_button (); ?>
131141 </form>
132142 </div>
0 commit comments