github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/docs/transactions/index.md (about)

     1  ---
     2  layout: default
     3  title: Transactions
     4  nav_order: 5
     5  has_children: false
     6  ---
     7  
     8  # Transactions
     9  
    10  In order to fund contracts and Chainlink nodes, you need to make a few transactions on the blockchain you're working with. By default, sending a transaction will block the test until the transaction is confirmed on the blockchain, then move on. If you want to change this behavior, check the section on [parallel transactions](#parallel-transactions).
    11  
    12  ## Funding Contracts
    13  
    14  Most on-chain objects like contracts have some sort of `Fund(...)` method that can be used to send an amount of funds to that contract's address.
    15  
    16  ```go
    17  // Funds the ocrContract from the default private key.
    18  // Fund this contract with 1 ETH
    19  err := ocrContract.Fund(big.NewFloat(1))
    20  // Funds the same contract with .001 ETH
    21  err = ocrContract.Fund(big.NewFloat(.001))
    22  ```
    23  
    24  ## Funding Chainlink Nodes
    25  
    26  Chainlink nodes are easy to fund with the handy [actions package](https://pkg.go.dev/github.com/smartcontractkit/integrations-framework/actions).
    27  
    28  ```go
    29  // Funds each node in the `chainlinkNodes` array with .01 of the network's native currency
    30  err := actions.FundChainlinkNodes(chainlinkNodes, defaultNetwork, big.NewFloat(.01))
    31  ```
    32  
    33  ## Parallel Transactions
    34  
    35  Sometimes you'll want to fund a bunch of addresses or launch a few contracts that have no relation to each other. Rather than waiting for each transaction or contract deployment to be confirmed before moving on to the next one, you can make use of parallel transactions.
    36  
    37  ```go
    38  // Any transactions made after this line will be submitted instantly to the blockchain without waiting for previous ones.
    39  defaultNetwork.ParallelTransactions(true)
    40  ```
    41  
    42  This can seriously speed up some test setups and executions, for example, if you want to fund your Chainlink nodes and a couple deployed contracts at the beginning of your test. But be wary, as some events depend on previous ones being confirmed, like funding a contract only after it has been deployed and confirmed on chain. For that, utilize the `defaultNetwork.WaitForEvents()` method call to halt running.
    43  
    44  ```go
    45  // Set parallel transactions
    46  defaultNetwork.ParallelTransactions(true)
    47  
    48  // A pretend method to deploy a bunch of contracts and return them as a list
    49  someListOfContracts := deploySomeContracts()
    50  // Fund Chainlink nodes, which don't depend on contracts being confirmed on chain
    51  err := actions.FundChainlinkNodes(chainlinkNodes, defaultNetwork, big.NewFloat(.01))
    52  
    53  // Wait for all on-chain events started above to complete before moving on
    54  err = defaultNetwork.WaitForEvents()
    55  
    56  // Fund the deployed contracts
    57  for _, contract := range someListOfContracts {
    58    contract.Fund(big.NewFloat(1))
    59  }
    60  
    61  // Wait for the contract funding to go through before moving on
    62  err = defaultNetwork.WaitForEvents()
    63  ```
    64  
    65  If you see errors in funding or interacting with contracts that imply the contracts don't exist, it's likely you set parallel transactions to `true` and failed to `WaitForEvents()` at an appropriate time. This feature is handy to speed up your test setups and executions, but can trip you up if not properly monitored, so take care.