> For the complete documentation index, see [llms.txt](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/basics/6.-foundry/cast/cast-send.md).

# cast send

### 블록체인의 상태 변경

`cast send`는 **상태를 변경하는 스마트 컨트랙트 함수**를 호출할 때 사용하는 명령어이다.

<figure><img src="https://2462457462-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLf9vwRuaws92ULgGvzTi%2Fuploads%2FuD8qthRclCDwzupg08k1%2Fimage.png?alt=media&amp;token=992ae5c3-d633-4bb9-9bb3-e209f5922a0a" alt=""><figcaption></figcaption></figure>

예를 들어 토큰을 전송하거나, 값을 저장하거나, 상태 변수를 업데이트하는 작업 등에 사용된다.

* **트랜잭션이 발생**하므로 가스가 소모된다.
* 따라서 **개인키**를 통해 서명해야 한다.

***

### 명령어 형식

```bash
$ cast send <컨트랙트 주소> \
  --rpc-url <rpc-url> \
  --private-key <개인키> \
  "<함수 시그니처>" <인자들>
```

***

### 예시

아래는 send를 이용해 이전 forge create에서 배포했던 컨트랙트의 상태변수 number를 변경하는 setNumber() 함수를 호출하여 number에 10을 넣는예제이다.

#### 대상 컨트랙트

```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

contract Counter {
    uint256 public number;

    function setNumber(uint256 newNumber) public {
        number = newNumber;
    }

    function increment() public {
        number++;
    }
}
```

***

#### 배포 주소 : 0x3529415c3DDBD561B7DC03483EadF334b5422ef1

***

#### cast send 명령어

```bash
$ cast send 0x3529415c3DDBD561B7DC03483EadF334b5422ef1 \
  --rpc-url <rpc-url> \
  --private-key <개인키> \
  "setNumber(uint256)" 10
```

***

#### 실행 결과 예시

* 트랜잭션 해시
* 가스 사용량
* 블록 넘버 등 출력됨

<figure><img src="https://2462457462-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLf9vwRuaws92ULgGvzTi%2Fuploads%2Fl85TWw4PbxYk9ngU9Fgt%2Fimage%20(8).png?alt=media&amp;token=5e8f4243-98a8-4cd3-91c8-403180e0a959" alt=""><figcaption></figcaption></figure>
