github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/rpcclient/nep17/doc_test.go (about) 1 package nep17_test 2 3 import ( 4 "context" 5 "math/big" 6 7 "github.com/nspcc-dev/neo-go/pkg/encoding/address" 8 "github.com/nspcc-dev/neo-go/pkg/rpcclient" 9 "github.com/nspcc-dev/neo-go/pkg/rpcclient/actor" 10 "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" 11 "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17" 12 "github.com/nspcc-dev/neo-go/pkg/util" 13 "github.com/nspcc-dev/neo-go/pkg/wallet" 14 ) 15 16 func ExampleTokenReader() { 17 // No error checking done at all, intentionally. 18 c, _ := rpcclient.New(context.Background(), "url", rpcclient.Options{}) 19 20 // Safe methods are reachable with just an invoker, no need for an account there. 21 inv := invoker.New(c, nil) 22 23 // NEP-17 contract hash. 24 nep17Hash := util.Uint160{9, 8, 7} 25 26 // And a reader interface. 27 n17 := nep17.NewReader(inv, nep17Hash) 28 29 // Get the metadata. Even though these methods are implemented in neptoken package, 30 // they're available for NEP-17 wrappers. 31 symbol, _ := n17.Symbol() 32 supply, _ := n17.TotalSupply() 33 _ = symbol 34 _ = supply 35 36 // Account hash we're interested in. 37 accHash, _ := address.StringToUint160("NdypBhqkz2CMMnwxBgvoC9X2XjKF5axgKo") 38 39 // Get account balance. 40 balance, _ := n17.BalanceOf(accHash) 41 _ = balance 42 } 43 44 func ExampleToken() { 45 // No error checking done at all, intentionally. 46 w, _ := wallet.NewWalletFromFile("somewhere") 47 defer w.Close() 48 49 c, _ := rpcclient.New(context.Background(), "url", rpcclient.Options{}) 50 51 // Create a simple CalledByEntry-scoped actor (assuming there is an account 52 // inside the wallet). 53 a, _ := actor.NewSimple(c, w.Accounts[0]) 54 55 // NEP-17 contract hash. 56 nep17Hash := util.Uint160{9, 8, 7} 57 58 // Create a complete NEP-17 contract representation. 59 n17 := nep17.New(a, nep17Hash) 60 61 tgtAcc, _ := address.StringToUint160("NdypBhqkz2CMMnwxBgvoC9X2XjKF5axgKo") 62 63 // Send a transaction that transfers one token to another account. 64 txid, vub, _ := n17.Transfer(a.Sender(), tgtAcc, big.NewInt(1), nil) 65 _ = txid 66 _ = vub 67 }