-
-
Save andreystarkov/2223fe4952d49bb76578614b2aaa0c47 to your computer and use it in GitHub Desktop.
eos testnet faucet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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