{"id":13651357,"url":"https://github.com/Aphoh/go-substrate-gen","last_synced_at":"2025-04-22T22:31:04.118Z","repository":{"id":57710020,"uuid":"476874266","full_name":"Aphoh/go-substrate-gen","owner":"Aphoh","description":"https://github.com/Aphoh/go-substrate-gen","archived":false,"fork":false,"pushed_at":"2023-08-30T04:23:44.000Z","size":147,"stargazers_count":7,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T02:43:10.506Z","etag":null,"topics":["golang","substrate"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aphoh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2022-04-01T21:33:28.000Z","updated_at":"2024-06-25T08:56:39.000Z","dependencies_parsed_at":"2024-01-03T05:14:14.425Z","dependency_job_id":"f462861d-bd5f-49e9-80b6-c8f58c6defe9","html_url":"https://github.com/Aphoh/go-substrate-gen","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aphoh%2Fgo-substrate-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aphoh%2Fgo-substrate-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aphoh%2Fgo-substrate-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aphoh%2Fgo-substrate-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aphoh","download_url":"https://codeload.github.com/Aphoh/go-substrate-gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250333910,"owners_count":21413475,"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":["golang","substrate"],"created_at":"2024-08-02T02:00:48.525Z","updated_at":"2025-04-22T22:31:03.838Z","avatar_url":"https://github.com/Aphoh.png","language":"Go","funding_links":[],"categories":["Client Libraries"],"sub_categories":[],"readme":"# Go Substrate Code Generator\n\nA tool that generates boilerplate code for substrate-based chains (calls, storage access, events, etc) using [`go-substrate-rpc-client`](github.com/centrifuge/go-substrate-rpc-client).\n\nThis uses the metadata Json RPC provided by substrate-based chains, which you can get by doing:\n```\ncurl -L -X POST -H \"Content-Type: application/json\" -d '{\"id\":1, \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\"}' https://rpc.polkadot.io \u003e polkadot-meta.json\n```\nJust replace `rpc.polkadot.io` with your own server.\n### Installation\nClone the repo, run `go install ./...` and make sure it's on your path.\n\n\n### Using `go generate`\n\nMake a submodule in your go project. Place a `metadata.json` and the following `mymodule.go` file in it\n```\n//go:generate go-substrate-gen metadata.json \"github.com/my/package/mymodule\"\n\npackage mymodule\n```\n\nThen run `go generate ./...` and it'll generate code for each pallet in the `mymodule` directory.\n\n### Calling manually\n```\ngo-substrate-gen meta.json \"github.com/my/package/submodule/for/code\" \n```\n\n### Getting Metadata\nThere is code included under `json-gen` to fetch a human-readable version of the json from a locally running substrate node in dev mode.\nView [the readme](json-gen/README.md) for instructions.\n\n### Architecture and Design\nPlease read the [documentation](doc/architecture.md), which describes the received metadata's structure, and also gives an overview of the code's structure.\n\n### Calling code\nExample for `pallet_balances`\n\n```golang\n// Transfer some liquid free balance to another account.\n//\n// `transfer` will set the `FreeBalance` of the sender and receiver.\n// If the sender's account is below the existential deposit as a result\n// of the transfer, the account will be reaped.\n//\n// The dispatch origin for this call must be `Signed` by the transactor.\n//\n// # \u003cweight\u003e\n// - Dependent on arguments but not critical, given proper implementations for input config\n//   types. See related functions below.\n// - It contains a limited number of reads and writes internally and no complex\n//   computation.\n//\n// Related functions:\n//\n//   - `ensure_can_withdraw` is always called internally but has a bounded complexity.\n//   - Transferring balances to accounts that did not exist before will cause\n//     `T::OnNewAccount::on_new_account` to be called.\n//   - Removing enough funds from an account will trigger `T::DustRemoval::on_unbalanced`.\n//   - `transfer_keep_alive` works the same way as `transfer`, but has an additional check\n//     that the transfer will not kill the origin account.\n// ---------------------------------\n// - Origin account is already in memory, so no DB operations for them.\n// # \u003c/weight\u003e\nfunc MakeTransferCall(dest0 *MultiAddress, value1 *types.UCompact) (types.Call, error) {...}\n...\n```\n\n### Storage code\n\n```golang\n// Make a storage key for Account\n//  The Balances pallet example of storing the balance of an account.\n//\n//  # Example\n//\n//  \n//   impl pallet_balances::Config for Runtime {\n//     type AccountStore = StorageMapShim\u003cSelf::Account\u003cRuntime\u003e, frame_system::Provider\u003cRuntime\u003e, AccountId, Self::AccountData\u003cBalance\u003e\u003e\n//   }\n//  \n//\n//  You can also store the balance of an account in the `System` pallet.\n//\n//  # Example\n//\n//  ```nocompile\n//   impl pallet_balances::Config for Runtime {\n//    type AccountStore = System\n//   }\n//  ```\n//\n//  But this comes with tradeoffs, storing account balances in the system pallet stores\n//  `frame_system` data alongside the account data contrary to storing account balances in the\n//  `Balances` pallet, which uses a `StorageMap` to store balances data only.\n//  NOTE: This is only used in the case that this pallet is used to store balances.\nfunc MakeAccountStorageKey(byteArray0 [32]byte) (types.StorageKey, error) {...}\n\nfunc GetAccount(state *state.State, bhash types.Hash, byteArray0 [32]byte) (ret AccountData, err error) {...}\n...\n```\n\n### Types\n\n```golang\n// Generated pallet_balances_AccountData\ntype AccountData struct {\n\t// Field 0 with TypeId=6\n\tFree types.U128\n\t// Field 1 with TypeId=6\n\tReserved types.U128\n\t// Field 2 with TypeId=6\n\tMiscFrozen types.U128\n\t// Field 3 with TypeId=6\n\tFeeFrozen types.U128\n}\n\n// Generated SpRuntimeMultiaddressMultiAddress with id=188\ntype MultiAddress struct {\n\tIsId              bool\n\tAsIdField0        [32]byte\n\tIsIndex           bool\n\tAsIndexField0     struct{}\n\tIsRaw             bool\n\tAsRawField0       []byte\n\tIsAddress32       bool\n\tAsAddress32Field0 [32]byte\n\tIsAddress20       bool\n\tAsAddress20Field0 [20]byte\n}\n\nfunc (ty MultiAddress) Encode(encoder scale.Encoder) (err error) {...}\n\nfunc (ty *MultiAddress) Decode(decoder scale.Decoder) (err error) {...}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAphoh%2Fgo-substrate-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAphoh%2Fgo-substrate-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAphoh%2Fgo-substrate-gen/lists"}