Querying Contracts

After the contract is successfully deployed, you can call querying methods of the contract by the new contract instance. Here is a complete example of querying a contract.

package main
import (
	store "...The path of the store.go file..."
	"fmt"
	"log"
	"github.com/PhoenixGlobal/Phoenix-Chain-SDK/ethereum/ethclient"
	"github.com/PhoenixGlobal/Phoenix-Chain-SDK/libs/common"
)
func main() {
	client, err := ethclient.Dial("https://dataseed1.phoenix.global/rpc")
	if err != nil {
		log.Fatal(err)
	}
	contractAddress := common.HexToAddress("0x9aC8B849A8b6Fc14F8dEcfa6A22dB41671B38eFB")
	contractInstance, err := store.NewStore(contractAddress, client)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("contract is loaded")
	version, err := contractInstance.Version(nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(version) // "1.0.0"
}

Last updated