{"id":18437837,"url":"https://github.com/zilliqa/gozilliqa-sdk","last_synced_at":"2025-04-05T00:06:35.313Z","repository":{"id":39850511,"uuid":"208000729","full_name":"Zilliqa/gozilliqa-sdk","owner":"Zilliqa","description":"Zilliqa golang sdk","archived":false,"fork":false,"pushed_at":"2024-10-23T09:00:03.000Z","size":1421,"stargazers_count":34,"open_issues_count":11,"forks_count":29,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-28T23:08:53.094Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zilliqa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-12T08:24:12.000Z","updated_at":"2025-03-20T09:27:05.000Z","dependencies_parsed_at":"2024-06-18T13:59:29.103Z","dependency_job_id":"552ae370-a49d-4767-81c8-e63a372db472","html_url":"https://github.com/Zilliqa/gozilliqa-sdk","commit_stats":{"total_commits":301,"total_committers":12,"mean_commits":"25.083333333333332","dds":0.09302325581395354,"last_synced_commit":"369a05d8c3b8a78cd723eec6dbe4bd78eefd6ac8"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zilliqa%2Fgozilliqa-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zilliqa%2Fgozilliqa-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zilliqa%2Fgozilliqa-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zilliqa%2Fgozilliqa-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zilliqa","download_url":"https://codeload.github.com/Zilliqa/gozilliqa-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247266563,"owners_count":20910836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T06:16:23.201Z","updated_at":"2025-04-05T00:06:35.293Z","avatar_url":"https://github.com/Zilliqa.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"### gozilliqa-sdk\n\nThe golang version of zilliqa blockchain library\n\n#### Requirements\n\ngolang environment:\n\n* [download golang](https://golang.org/dl/)\n* [installation instructions](https://golang.org/doc/install)\n\n#### Installation\n\nThis sdk uses `go mod` to manage its dependent libraries.\n\nTo install dependencies:\n\n```go\ngo get ./...\n```\n\nTo build:\n\n```go\ngo build ./...\n```\n\nTo run the unit tests (which require access to the Zilliqa testnet):\n\n```go\ngo test ./...\n```\n\n#### Supports\n\n##### Multisig support\n\n- [x] aggregatedPubKey\n- [x] multiVerify\n- [x] tx block serialization\n- [x] ds block serialization  \n- [x] verify tx block\n- [x] verify ds block\n\n#### State proof\n\n- [x] getStateProof\n- [x] verifyStateProof\n\n#### ChainWalker\n\n- [x] traversalBlock\n- [x] websocket\n\n##### Account API\n\n- [x] fromFile\n- [x] toFile\n- [x] newHDAccount (with default derivation path \"m/44'/313'/0'/0/${index}\")\n- [x] newHDAccountWithDerivationPath\n\n##### Wallet API\n\n- [x] createAccount\n- [x] addByPrivateKey addByKeyStore\n- [x] remove\n- [x] setDefault\n- [x] signTransaction (default account)\n- [x] signTransactionWith (specific account)\n- [x] SignBatch\n- [x] SendBatch (using JSON-RPC batch request or WaitGroup)\n\n##### TransactionFactory Transaction\n\n- [x] sendTransaction\n- [x] trackTx\n- [x] confirm\n- [x] isPending isInitialised isConfirmed isRejected\n\n##### ContractFactory Contract\n\n- [x] deploy\n- [x] call\n- [x] isInitialised isDeployed isRejected\n- [x] getState\n- [x] getAddressForContract\n\n\n##### Crypto API\n\n- [x] getDerivedKey (PBKDF2 and Scrypt)\n- [x] generatePrivateKey\n- [x] Schnorr.sign\n- [x] Schnorr.verify\n- [x] getPublicKeyFromPrivateKey\n- [x] getAddressFromPublicKey\n- [x] getAddressFromPrivateKey\n- [x] encryptPrivateKey\n- [x] decryptPrivateKey\n\n##### JSON-RPC API\n\nBlockchain-related methods\n\n- [x] getNetworkId\n- [x] getVersion\n- [x] getNodeType\n- [x] getNumPeers\n- [x] getBlockchainInfo\n- [x] getShardingStructure\n- [x] getDsBlock\n- [x] getLatestDsBlock\n- [x] getNumDSBlocks\n- [x] getDSBlockRate\n- [x] getDSBlockListing\n- [x] getTxBlock\n- [x] getLatestTxBlock\n- [x] getNumTxBlocks\n- [x] getTxBlockRate\n- [x] getTxBlockListing\n- [x] getNumTransactions\n- [x] getTransactionRate\n- [x] getCurrentMiniEpoch\n- [x] getCurrentDSEpoch\n- [x] getPrevDifficulty\n- [x] getPrevDSDifficulty\n\nTransaction-related methods\n\n- [x] createTransaction\n- [x] getTransaction\n- [x] getRecentTransactions\n- [x] getTransactionsForTxBlock\n- [x] getTransactionsForTxBlockEx\n- [x] getTxnBodiesForTxBlock\n- [x] getTxnBodiesForTxBlockEx\n- [x] getNumTxnsTxEpoch\n- [x] getNumTxnsDSEpoch\n- [x] getMinimumGasPrice\n\nContract-related methods\n\n- [x] getSmartContractCode\n- [x] getSmartContractInit\n- [x] getSmartContractState\n- [x] getSmartContracts\n- [x] getContractAddressFromTransactionID\n\nAccount-related methods\n\n- [x] getBalance\n\n##### Validation\n\n- [x] isAddress\n- [x] isPublicjKey\n- [x] isPrivateKey\n- [x] isSignature\n\n##### Util\n\n- [x] byteArrayToHexString\n- [x] hexStringToByteArray\n- [x] generateMac\n- [x] isByteString\n- [x] encodeTransactionProto\n- [x] toChecksumAddress\n- [x] isValidChecksumAddress\n- [x] bech32 encode decode\n- [x] isBech32\n- [x] fromBech32Address toBech32Address\n\n#### Quick Start\n\n##### Generate a large number of private keys:\n\n```go\nfunc TestGeneratePrivateKey(t *testing.T) {\n\tfor i := 0; i \u003c 100000; i++ {\n\t\tprivateKey, err := GeneratePrivateKey()\n\t\tif err != nil {\n\t\t\tpanic(\"cannot generate private key\")\n\t\t}\n\n\t\tprikeys := LaksaGo.EncodeHex(privateKey[:])\n\t\tif len(prikeys) != 64 {\n\t\t\tpanic(\"generate private key error\")\n\t\t}\n\t\tprintln(\"private key = \" + prikeys)\n\t\tpublickKey := GetPublicKeyFromPrivateKey(LaksaGo.DecodeHex(prikeys), true)\n\t\tpubkeys := LaksaGo.EncodeHex(publickKey)\n\t\tif len(pubkeys) != 66 {\n\t\t\tpanic(\"generate public key error\")\n\t\t}\n\t\tprintln(\"public key = \" + pubkeys)\n\n\t}\n}\n```\n\n##### Encrypt private key to a keystore file:\n\n```go\nfunc TestKeystore_EncryptPrivateKey(t *testing.T) {\n\tks := NewDefaultKeystore()\n\tkv, err := ks.EncryptPrivateKey(util.DecodeHex(\"24180e6b0c3021aedb8f5a86f75276ee6fc7ff46e67e98e716728326102e91c9\"), []byte(\"xiaohuo\"), 0)\n\tif err != nil {\n\t\tt.Error(err.Error())\n\t} else {\n\t\tprintln(kv)\n\t}\n}\n```\n\n##### Decrypt private key from a keystore file:\n\n```go\nfunc TestKeystore_DecryptPrivateKey(t *testing.T) {\n\tjson := \"{\\\"address\\\":\\\"b5c2cdd79c37209c3cb59e04b7c4062a8f5d5271\\\",\\\"id\\\":\\\"979daaf9-daf1-4002-8656-3cea134c9518\\\",\\\"version\\\":3,\\\"crypto\\\":{\\\"cipher\\\":\\\"aes-128-ctr\\\",\\\"ciphertext\\\":\\\"26be10cdae0f397bdeead38e7fcc179957dd5e7ef95a1f0f53f37b7ad1355159\\\",\\\"kdf\\\":\\\"pbkdf2\\\",\\\"mac\\\":\\\"81d8e60bc08237e4ba154c0b27ad08562821d8c602ee8a492434128de48b66bc\\\",\\\"cipherparams\\\":{\\\"iv\\\":\\\"fc714ad6267c35a2df4cb3f8b8b3cc0d\\\"},\\\"kdfparams\\\":{\\\"n\\\":8192,\\\"c\\\":262144,\\\"r\\\":8,\\\"p\\\":1,\\\"dklen\\\":32,\\\"salt\\\":\\\"e22ef8a67a59299cee1532b6c6967bdfb0e75ca3c5dff852f9d8daa04683b0c1\\\"}}}\"\n\n\tks := NewDefaultKeystore()\n\tprivateKey, err := ks.DecryptPrivateKey(json, \"xiaohuo\")\n\tif err != nil {\n\t\tt.Error(err.Error())\n\t} else {\n\t\tif strings.Compare(strings.ToLower(privateKey), \"24180e6b0c3021aedb8f5a86f75276ee6fc7ff46e67e98e716728326102e91c9\") != 0 {\n\t\t\tt.Error(\"decrypt private key failed\")\n\t\t}\n\t}\n}\n```\n\n##### Send a transfer transaction\n\n```go\nfunc TestSendTransaction(t *testing.T) {\n\tif os.Getenv(\"CI\") != \"\" {\n\t\tt.Skip(\"Skipping testing in CI environment\")\n\t}\n\twallet := NewWallet()\n\twallet.AddByPrivateKey(\"e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930\")\n\tprovider := provider2.NewProvider(\"https://dev-api.zilliqa.com/\")\n\n\tgasPrice, err := provider.GetMinimumGasPrice()\n\tassert.Nil(t, err, err)\n\n\ttx := \u0026transaction.Transaction{\n\t\tVersion:      strconv.FormatInt(int64(util.Pack(333, 1)), 10),\n\t\tSenderPubKey: \"0246E7178DC8253201101E18FD6F6EB9972451D121FC57AA2A06DD5C111E58DC6A\",\n\t\tToAddr:       \"4BAF5faDA8e5Db92C3d3242618c5B47133AE003C\",\n\t\tAmount:       \"10000000\",\n\t\tGasPrice:     gasPrice,\n\t\tGasLimit:     \"1\",\n\t\tCode:         \"\",\n\t\tData:         \"\",\n\t\tPriority:     false,\n\t}\n\n\terr2 := wallet.Sign(tx, *provider)\n\tassert.Nil(t, err2, err2)\n\n\trsp, err3 := provider.CreateTransaction(tx.ToTransactionPayload())\n\tassert.Nil(t, err3, err3)\n\tassert.Nil(t, rsp.Error, rsp.Error)\n\n\tresMap := rsp.Result.(map[string]interface{})\n\thash := resMap[\"TranID\"].(string)\n\tfmt.Printf(\"hash is %s\\n\", hash)\n\ttx.Confirm(hash, 1000, 3, provider)\n\tassert.True(t, tx.Status == core.Confirmed)\n}\n```\n\n#### Send a batch of payment transactions\n\n```go\nfunc TestBatchSendTransaction(t *testing.T) {\n\truntime.GOMAXPROCS(runtime.NumCPU())\n\tif os.Getenv(\"CI\") != \"\" {\n\t\tt.Skip(\"Skipping testing in CI environment\")\n\t}\n\twallet := NewWallet()\n\twallet.AddByPrivateKey(\"e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930\")\n\tprovider := provider2.NewProvider(\"https://dev-api.zilliqa.com/\")\n\n\tgasPrice, err := provider.GetMinimumGasPrice()\n\tassert.Nil(t, err, err)\n\n\tvar transactions []*transaction.Transaction\n\tfor i := 0; i \u003c 100; i++ {\n\t\ttxn := \u0026transaction.Transaction{\n\t\t\tVersion:      strconv.FormatInt(int64(util.Pack(333, 1)), 10),\n\t\t\tSenderPubKey: \"0246E7178DC8253201101E18FD6F6EB9972451D121FC57AA2A06DD5C111E58DC6A\",\n\t\t\tToAddr:       \"4BAF5faDA8e5Db92C3d3242618c5B47133AE003C\",\n\t\t\tAmount:       \"10000000\",\n\t\t\tGasPrice:     gasPrice,\n\t\t\tGasLimit:     \"1\",\n\t\t\tCode:         \"\",\n\t\t\tData:         \"\",\n\t\t\tPriority:     false,\n\t\t}\n\n\t\ttransactions = append(transactions, txn)\n\t}\n\n\terr2 := wallet.SignBatch(transactions, *provider)\n\tassert.Nil(t, err2, err2)\n\n\tbatchSendingResult,err := wallet.SendBatchOneGo(transactions, *provider)\n\tif err != nil {\n\t\tt.Fail()\n\t} else {\n\t\tfmt.Println(batchSendingResult)\n\t}\n}\n```\n\n##### Deploy a smart contract\n\n```go\nfunc TestContract_Deploy(t *testing.T) {\n\tif os.Getenv(\"CI\") != \"\" {\n\t\tt.Skip(\"Skipping testing in CI environment\")\n\t}\n\thost := \"https://dev-api.zilliqa.com/\"\n\tprivateKey := \"e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930\"\n\tchainID := 333\n\tmsgVersion := 1\n\n\tpublickKey := keytools.GetPublicKeyFromPrivateKey(util.DecodeHex(privateKey), true)\n\taddress := keytools.GetAddressFromPublic(publickKey)\n\tpubkey := util.EncodeHex(publickKey)\n\tprovider := provider2.NewProvider(host)\n\n\twallet := account.NewWallet()\n\twallet.AddByPrivateKey(privateKey)\n\n\tcode, _ := ioutil.ReadFile(\"./fungible.scilla\")\n\tinit := []core.ContractValue{\n\t\t{\n\t\t\t\"_scilla_version\",\n\t\t\t\"Uint32\",\n\t\t\t\"0\",\n\t\t},\n\t\t{\n\t\t\t\"owner\",\n\t\t\t\"ByStr20\",\n\t\t\t\"0x\" + address,\n\t\t},\n\t\t{\n\t\t\t\"total_tokens\",\n\t\t\t\"Uint128\",\n\t\t\t\"1000000000\",\n\t\t},\n\t\t{\n\t\t\t\"decimals\",\n\t\t\t\"Uint32\",\n\t\t\t\"0\",\n\t\t},\n\t\t{\n\t\t\t\"name\",\n\t\t\t\"String\",\n\t\t\t\"BobCoin\",\n\t\t},\n\t\t{\n\t\t\t\"symbol\",\n\t\t\t\"String\",\n\t\t\t\"BOB\",\n\t\t},\n\t}\n\tcontract := Contract{\n\t\tCode:     string(code),\n\t\tInit:     init,\n\t\tSigner:   wallet,\n\t\tProvider: provider,\n\t}\n\n\tbalAndNonce, _ := provider.GetBalance(address)\n\n\tgasPrice, _ := provider.GetMinimumGasPrice()\n\n\tdeployParams := DeployParams{\n\t\tVersion:      strconv.FormatInt(int64(util.Pack(chainID, msgVersion)), 10),\n\t\tNonce:        strconv.FormatInt(balAndNonce.Nonce+1, 10),\n\t\tGasPrice:     gasPrice,\n\t\tGasLimit:     \"10000\",\n\t\tSenderPubKey: pubkey,\n\t}\n\n\ttx, err := contract.Deploy(deployParams)\n\tassert.Nil(t, err, err)\n\ttx.Confirm(tx.ID, 1000, 10, provider)\n\tassert.True(t, tx.Status == core.Confirmed)\n}\n```\n\n##### Call a smart contract\n\n```go\nfunc TestContract_Call(t *testing.T) {\n\tif os.Getenv(\"CI\") != \"\" {\n\t\tt.Skip(\"Skipping testing in CI environment\")\n\t}\n\thost := \"https://dev-api.zilliqa.com/\"\n\tprivateKey := \"e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930\"\n\tchainID := 333\n\tmsgVersion := 1\n\n\tpublickKey := keytools.GetPublicKeyFromPrivateKey(util.DecodeHex(privateKey), true)\n\taddress := keytools.GetAddressFromPublic(publickKey)\n\tpubkey := util.EncodeHex(publickKey)\n\tprovider := provider2.NewProvider(host)\n\n\twallet := account.NewWallet()\n\twallet.AddByPrivateKey(privateKey)\n\n\tcontract := Contract{\n\t\tAddress:  \"bd7198209529dC42320db4bC8508880BcD22a9f2\",\n\t\tSigner:   wallet,\n\t\tProvider: provider,\n\t}\n\n\targs := []core.ContractValue{\n\t\t{\n\t\t\t\"to\",\n\t\t\t\"ByStr20\",\n\t\t\t\"0x\" + address,\n\t\t},\n\t\t{\n\t\t\t\"tokens\",\n\t\t\t\"Uint128\",\n\t\t\t\"10\",\n\t\t},\n\t}\n\n\tbalAndNonce, err := provider.GetBalance(\"9bfec715a6bd658fcb62b0f8cc9bfa2ade71434a\")\n\tassert.Nil(t, err, err)\n\tn := balAndNonce.Nonce + 1\n\tgasPrice, _ := provider.GetMinimumGasPrice()\n\n\tparams := CallParams{\n\t\tNonce:        strconv.FormatInt(n, 10),\n\t\tVersion:      strconv.FormatInt(int64(util.Pack(chainID, msgVersion)), 10),\n\t\tGasPrice:     gasPrice,\n\t\tGasLimit:     \"1000\",\n\t\tSenderPubKey: pubkey,\n\t\tAmount:       \"0\",\n\t}\n\n\ttx, err2 := contract.Call(\"Transfer\", args, params, true)\n\tassert.Nil(t, err2, err2)\n\ttx.Confirm(tx.ID, 1000, 3, provider)\n\tassert.True(t, tx.Status == core.Confirmed)\n}\n```\n\n#### A note on versions\n\nThis module was originally referenced using pseudo-versions and releases up to v2.4.0 were published as github releases without backward compatibility.\nSadly, go modules require version `n` (`n\u003e=2`) modules to have a `/v\u003cn\u003e` tag in their paths, and so we now do.\nSince this is a breaking change, we've elected to bump the major version to 3, which means that in fact the go module path is now `/v3`.\nHopefully the version churn will now stop.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzilliqa%2Fgozilliqa-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzilliqa%2Fgozilliqa-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzilliqa%2Fgozilliqa-sdk/lists"}