Messrs, i want make app just like NBA_TOP where should i start ,i had read candence, Flow Emulator, go sdk ,as a Back end ,where could make test env
now ,i want make a go api /create_acount
i follow the example create random seed an string len 32
then get the privateKey publicKey
then use templates.CreateAccount get a scrpit
c, err := client.New(“access.devnet.nodes.onflow.org:9000”, grpc.WithInsecure())
err = tx.SignEnvelope(payer, payerKey.Index, payerSigner)
NewUserAddress = accountCreatedEvent.Address()
finally address is 0000000000000000
Why the address is 0000000000000000
and i don`t konw which step mistake ,there is no panic happen
next is my code
func (this *MarketController) Create_uer() {
o := orm.NewOrmUsingDB(“default”) // 创建一个 Ormer
Name := this.GetString(“username”)
if Name != “” {User := new(models.User) User.Name = Name
// start make NFT relevant
///
ctx := context.Background()random_seed := beegoutils.Random_string() // 为账户生成一个新的私钥 // 注意: 这只是一个例子, 请使用安全的方式随机生成种子 seed := []byte(random_seed) //fmt.Println("seed",seed) privateKey, _ := crypto.GeneratePrivateKey(crypto.ECDSA_secp256k1, seed) encPrivateKey := privateKey.Encode() // 得到公钥 publicKey := privateKey.PublicKey() // 从公钥中构建一个用户密钥 accountKey := flow.NewAccountKey(). SetPublicKey(publicKey). SetHashAlgo(crypto.SHA3_256). // SHA3_256 哈希算法生成的密钥对 SetWeight(flow.AccountKeyWeightThreshold) // 授予这个密钥签名权重 //const rawPublicKey = "9cd98d436d111aab0718ab008a466d636a22ac3679d335b77e33ef7c52d9c8ce47cf5ad71ba38cedd336402aa62d5986dc224311383383c09125ec0636c0b042" //publicKey, err := crypto.DecodePublicKeyHex(crypto.ECDSA_P256, rawPublicKey) var address flow.Address // 生成一个帐户创建脚本 // 这将创建一个帐户,该帐户只有一个公钥,没有代码 script := templates.CreateAccount([]*flow.AccountKey{accountKey}, nil, address) // 连接到本地运行的模拟器 c, err := client.New("access.devnet.nodes.onflow.org:9000", grpc.WithInsecure()) if err != nil { panic(">>>> failed to connect to emulator") } signer := crypto.NewInMemorySigner(privateKey, accountKey.HashAlgo) payerSigner := signer payer := flow.HexToAddress("0xfc98bbf96a3ef8c1") acc, err := c.GetAccount(ctx, payer) println( " address >>> ",acc ,err ) payerKey := acc.Keys[0] //(flow.Address, *flow.AccountKey, crypto.Signer) //payer, payerKey, payerSigner := examples.ServiceAccount(c) //fmt.Println("|",script,payer,payerKey,payerSigner) // 获取 上一个区块头 //referenceBlockID := examples.GetReferenceBlockId(c) isSealed := true latestBlock, err := c.GetLatestBlock(ctx, isSealed) referenceBlockID := latestBlock.ID //script_value,_ := script.([]byte) tx := flow.NewTransaction(). SetScript(script.Script). SetGasLimit(100). SetProposalKey(payer, payerKey.Index, payerKey.SequenceNumber). SetPayer(payer) // Sign the transaction with the service account, which already exists // All new accounts must be created by an existing account // 业务签名 fmt.Println("payerKey",payerKey,payerKey.Index) fmt.Println("payerKey.Index",payerKey.Index) fmt.Println("payerSigner",payerSigner) err = tx.SignEnvelope(payer, payerKey.Index, payerSigner) if err != nil { panic("failed to sign transaction") } tx.SetReferenceBlockID(referenceBlockID) err = c.SendTransaction(ctx, *tx) if err != nil { fmt.Println("panic %v", err) panic("failed to send transaction ") } result, err := c.GetTransactionResult(ctx, tx.ID()) if err != nil { panic("failed to get transaction result") } // 获取地址 var myAddress flow.Address fmt.Println("result", result) for _, event := range result.Events { if event.Type == flow.EventAccountCreated { accountCreatedEvent := flow.AccountCreatedEvent(event) myAddress = accountCreatedEvent.Address() } } fmt.Println("Account created with address:", myAddress.Hex(), myAddress) // 准备新增用户所需数据 User.Address = fmt.Sprintf("%v", myAddress) User.PrivateKey = fmt.Sprintf("%v", privateKey) User.PublicKey = fmt.Sprintf("%v", publicKey) User.AccountKey = fmt.Sprintf("%v", accountKey) User.EncprivateKey = fmt.Sprintf("%v", encPrivateKey) fmt.Println("PrivateKey", privateKey, "publicKey", publicKey,"seed",seed,"encPrivateKey",encPrivateKey,) // 先 创建钱包 再创建用户 wallet := new(models.Wallet) wallet.Balance = 100 w_id, w_err := o.Insert(wallet) User.Wallet = wallet id, err := o.Insert(User) //返回插入成功消息 if err == nil && w_err == nil { this.Data["json"] = map[string]interface{}{ "code": 200, "message": "ok", "id": id, "wallet_id": w_id, } this.ServeJSON() } else { this.Data["json"] = map[string]interface{}{ "code": 200, "message": "fails", "id": id, "res": " inseart mysql fails %v, $v " + fmt.Sprintf("", err, ) + fmt.Sprintf("", w_err), } this.ServeJSON() }
} else {
this.Data[“json”] = map[string]interface{}{
“code”: 200, “message”: “fails”, “resule”: “miss username parmas”,
}
this.ServeJSON()
}}
What error are you getting?