Skip to content

hiroki-Fukumoto/smart-contract-demo

Repository files navigation

Geth DAPP DEMO

Implementing Smart Contract in the Golang

Requirement

  • Golang
  • Gin
  • Solidity
  • Ganache
  • go-ethereum
  • swag
  • Docker
  • Docker Compose

Set up

$ make setup

In "src/.env", set "GANACHE_HOST" to the network of the "geth" container

$ docker network inspect geth-dapp-demo-network
ex)

...
"Containers": {
    ...
    "xxxx" : {
        "Name": "geth", <- This is the name of the network to connect to the "geth" container.
    }
}

Usage

  1. Please change your Ganache private key.

You can check Ganache's Private Key with this command.

$ make exec-geth
$ ganache

Delete the leading "0x" of the acquired Private Key and paste it.

./src/contract_address/contract_address.go

priKey := "Your Private Key"
  1. Get a Contract address.
$ make up

go to http://localhost:8080/swagger/index.html call http://localhost:8080/api/v1/contract-address

  1. Please change your contract address.
./src/controller/hello.go

constantAddress = "Your Contract Address"
  1. call http://localhost:8080/api/v1/hello

If "Hello World" is displayed, it is successful!!

Compile solidity to Golang

Compile the code in the ./contracts and output the Golang code in the ./src/contracts.

$ make sol-compile sol={solidity file name} go={golang file name}

ex)
make sol-compile sol=Hello go=hello

Generate API docs

$ make generate-api-doc

SEE: https://github.com/swaggo/swag

Container up

$ make up

Container down

$ make down

Exec src container

$ make exec-src

Exec geth container

$ make exec-geth

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published