11package anvil
22
33import (
4+ "bufio"
45 "errors"
56 "fmt"
7+ "math/big"
68 "os/exec"
79 "sync/atomic"
10+
11+ "github.com/ethereum/go-ethereum/common"
12+ "github.com/ethereum/go-ethereum/rpc"
813)
914
1015// Node represents an active Anvil client
1116type Node struct {
17+ cli * rpc.Client
1218 running atomic.Bool
1319 cmd * exec.Cmd
1420}
@@ -36,7 +42,24 @@ func (n *Node) Start() error {
3642
3743 n .running .Store (true )
3844
39- return n .cmd .Start ()
45+ output , err := n .cmd .StdoutPipe ()
46+ if err != nil {
47+ return err // @TODO return specific error
48+ }
49+
50+ scanner := bufio .NewScanner (output )
51+
52+ err = n .cmd .Start ()
53+ if err != nil {
54+ return err
55+ }
56+
57+ scanner .Scan ()
58+ return nil
59+ }
60+
61+ func (n * Node ) SetBalance (account common.Address , balance * big.Int ) error {
62+ return n .cli .Call (nil , "anvil_setBalance" , account , balance )
4063}
4164
4265// Stop stops the anvil node
@@ -58,8 +81,8 @@ func WithBlockTime(seconds int) Option {
5881// WithBalance sets the initial balance of accounts.
5982//
6083// Equivalent to the `--balance <BALANCE>` flag
61- func WithBalance (balance int ) Option {
62- return []string {"--balance" , fmt .Sprintf ("%d " , balance )}
84+ func WithBalance (balance * big. Int ) Option {
85+ return []string {"--balance" , fmt .Sprintf ("%s " , balance )}
6386}
6487
6588// WithDerivationPath sets the derivation path for HD wallets.
@@ -173,8 +196,8 @@ func WithForkURL(url string) Option {
173196// WithForkBlockNumber forks from a specific block number.
174197//
175198// Equivalent to the `--fork-block-number <BLOCK>` flag
176- func WithForkBlockNumber (block int ) Option {
177- return []string {"--fork-block-number" , fmt .Sprintf ("%d " , block )}
199+ func WithForkBlockNumber (block * big. Int ) Option {
200+ return []string {"--fork-block-number" , fmt .Sprintf ("%s " , block )}
178201}
179202
180203// WithForkRetryBackoff sets initial retry backoff on fork errors.
0 commit comments