Skip to content

Instantly share code, notes, and snippets.

@vchengsong
Created October 22, 2018 02:58
Show Gist options
  • Save vchengsong/10b8851b0d975982770fdab10de3cdfa to your computer and use it in GitHub Desktop.
Save vchengsong/10b8851b0d975982770fdab10de3cdfa to your computer and use it in GitHub Desktop.
eos testnet faucet
package main
import(
"github.com/gin-gonic/gin"
//"net/http"
"github.com/eoscanada/eos-go"
token "github.com/eoscanada/eos-go/token"
"time"
)
func main() {
var api *eos.API
keyBag := eos.NewKeyBag()
keyBag.Add("***") //private key
api = eos.New("http://13.125.53.113:8888")
api.SetSigner(keyBag)
m:=make(map[string]time.Time)
router := gin.Default()
router.GET("/get-token/:name", func(c *gin.Context) {
name := c.Param("name")
if time.Since(m[name]) > time.Second * 300 {
}
if len(name) != 12 {
c.JSON(200, gin.H{
"success": "failed",
"message": "account length must be 12!",
})
}
// Transfer
act := token.NewTransfer(eos.AccountName("eosfaucet111"), eos.AccountName(name), eos.NewEOSAsset(1000),"faucet distribute")
_, err := api.SignPushActions(act)
if err != nil {
c.JSON(200, gin.H{
"success": "failed",
"message": err.Error(),
})
}else {
c.JSON(200, gin.H{
"success": "ok",
"message": "",
})
m[name] = time.Now()
}
})
router.Run(":8080")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment