# Custom Anchor Program

By far the most powerful feature of the Godot Solana SDK is the ability to integrate custom smart contract into your game through **AnchorProgram** class. The following example Tiny Adventure uses a smart contract heavily influenced by Solplay Jonas's [tutorial video](https://www.youtube.com/watch?v=_vQ3bSs3svs)

## Add AnchorProgram Node

In the root of your game's Scene Tree, or as an autoload, add **AnchorProgram** node into your game. One AnchorProgram is responsible for communication with one smart contract, so if your game needed more smart contracts, you'd add more nodes and to each one assign a different _Pid_ (Program ID)

## Import the IDL

Every Anchor smart contract comes with an IDL file that stores information on functions, accounts and other things the contract has. To be able to call a program, you need to have their respective IDL file imported into Godot.

Drag the IDL json file into _Json File_ slot in the node and click _Try From Json File_ to generate the IDL dictionary. This dictionary is going to allow to view and access the data within your scripts very trivial.

<figure><img src="https://3564869985-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbBsXAvrfZka40bbQ0val%2Fuploads%2FMjbtJhciHX6jX07S1h6u%2Fimage.png?alt=media&#x26;token=7a0e7360-16f4-4fd8-b08d-39b09d1400c4" alt=""><figcaption></figcaption></figure>

To know what accounts and arguments are needed for different instructions to be called, you can inspect the IDL dictionary. It is a very important thing to learn, because you will keep getting back to it for double checking the "Magic Strings" you need to input.

For example, here you see the program has 4 instructions. By clicking any dictionary in the array, you see that this one is called "restartLevel" and it has 4 accounts needed to be passed in and 1 argument:

<figure><img src="https://3564869985-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbBsXAvrfZka40bbQ0val%2Fuploads%2F4Sr00RHbTZWClrjAHFod%2Fimage.png?alt=media&#x26;token=850d2862-e178-492c-8552-7ee8de452248" alt=""><figcaption></figcaption></figure>

The argument, as you can see, is _chestPrice_ which needs to be a u64 integer. By checking all accounts and arguments, you will be ready to call this function!&#x20;

<figure><img src="https://3564869985-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbBsXAvrfZka40bbQ0val%2Fuploads%2FEXJxyJtQip1gu8PrOdt8%2Fimage.png?alt=media&#x26;token=6b3301a9-fe36-42fc-aef0-98cb5e7a34d5" alt=""><figcaption></figcaption></figure>

## Call The Function!

The following code restarts the Tiny Adventure game, by sending x amount of SOL as the chest prize, which the player would reclaim after reaching the game's end.



```
func init_game() -> void:
	var tiny_adventure_key:Pubkey = Pubkey.new_from_string(tiny_adventure_pid))
	var level_pda:Pubkey = Pubkey.new_pda(["Level1"],tiny_adventure_key)
	var vault_pda:Pubkey = Pubkey.new_pda(["Vault1"],tiny_adventure_key)
	
	var prize_in_lamports:int = int(chest_prize*pow(10,9))
	var instructions:Array[Instruction]
	
	var init_ix:Instruction = anchor_program.build_instruction("restartLevel",[
		level_pda, #gamedata
		vault_pda, #gamevault
		SolanaService.wallet.get_kp(), #signer
		SystemProgram.get_pid() #system program
	],
	AnchorProgram.u64(prize_in_lamports))
	
	instructions.append(init_ix)
	var transaction:Transaction = await SolanaService.transaction_manager.create_transaction(instructions)
	var tx_data:TransactionData = await SolanaService.transaction_manager.sign_and_send(transaction)
```

Please note that the PDA here was quite simple, consisting of just 1 parameter, so it was easily created using **Pubkey.new\_pda()** function. For a more complex PDA with more variables, it must be created from combining bytes. Check [here ](../core-concepts/program-derived-address-pda)for the explanation.

For a full demo of TinyAdventure, check _SolanaSDK -> Demos -> TinyAdventureDemo_ inside the imported addon.

There is also a far more complex Highscore Demo using [SOAR ](https://github.com/magicblock-labs/SOAR)program by Magicblock. You can find it in _SolanaSDK -> Demos -> HighscoreDemo_ in the addon!
