Skip to content

Commit cf1be72

Browse files
committed
docs(readme): add contract call example
1 parent 0ab00ee commit cf1be72

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,53 @@ func main() {
6161
}
6262
```
6363

64+
### Creating and Broadcasting a Token Transfer Transaction
65+
```go
66+
import (
67+
"github.com/balancednetwork/stacks-go-sdk/stacks"
68+
"github.com/balancednetwork/stacks-go-sdk/clarity"
69+
)
70+
71+
func main() {
72+
network := stacks.NewStacksMainnet()
73+
74+
contractAddress := "SP466FNC0P7JWTNM2R9T199QRZN1MYEDTAR0KP27"
75+
contractName := "contract-name"
76+
functionName := "function-name"
77+
senderAddress := "SP1P72Z3704VMT3DMHPP2CB8TGQWGDBHD3RPR9GZS"
78+
senderKey := []byte{...} // sender's private key
79+
80+
// Prepare function arguments
81+
arg1, _ := clarity.NewInt(123)
82+
arg2 := clarity.NewStringType("example")
83+
functionArgs := []clarity.ClarityValue{arg1, arg2}
84+
85+
// Create and sign the transaction
86+
tx, err := stacks.MakeContractCall(
87+
contractAddress,
88+
contractName,
89+
functionName,
90+
functionArgs,
91+
*network,
92+
senderAddress,
93+
senderKey,
94+
nil, // Let the function estimate the fee
95+
nil, // Let the function fetch the nonce
96+
)
97+
if err != nil {
98+
// Handle error
99+
}
100+
101+
// Broadcast the transaction
102+
txID, err := stacks.BroadcastTransaction(tx, network)
103+
if err != nil {
104+
// Handle error
105+
}
106+
107+
println("Contract call transaction broadcast successfully. Transaction ID:", txID)
108+
}
109+
```
110+
64111
### Working with Clarity Values
65112
```golang
66113
import (

0 commit comments

Comments
 (0)