Does anyone knows how to hardcode an address in smart contract?
Does anyone knows how to hardcode an address in smart contract?
The contract address is a hash of the code's `**stateInit**`.
If you change the initial storage of the contract, you are changing the future address of the contract. However, the future contract address is deterministic (known before you deploy), so you can pass the address to the storage, as part of the initializations of the contract.
For example, the Tact language down below shows how I can create a stateInit code to get Smart Contract address:
```solidity
contract Example {
any_int: Int;
init() {
self.any_int = 0;
}
receive("A") {
let contractInit: StateInit = initOf TargetContract(self.any_int, 666);
send(SendParameters{
to: contractAddress(contractInit),
value: 0,
mode: 0 + 64 + 128,
bounce: false
});
}
}
contract TargetContract {
counter: Int;
balance: Int;
init(input_counter: Int, input_balance: Int){
self.counter = input_counter;
self.balance = input_balance;
}
receive(){
// empty, means do nothing when receive empty body message.
}
}
```
As you can see, we can change the parameters that the second contract needs to predetermine the contract address since we got the `stateInit` code.
The contract address is a hash of the `**stateInit**` the code.
If you change the initial sotrage of the contract , you are changing the future address of the contract, but contract address is deterministic ( and its knowen before you deploy) you can pass the address to the sotrage , as part of the initializations of the contract.
For example, the Tact language down below shows how I can create a stateInit code to get Smart Contract address:
```
contract Example {
any_int: Int;
init() {
self.any_int = 0;
}
receive("A") {
let contractInit: StateInit = initOf TargetContract(self.any_int, 666);
send(SendParameters{
to: contractAddress(contractInit),
value: 0,
mode: 0 + 64 + 128,
bounce: false
});
}
}
contract TargetContract {
counter: Int;
balance: Int;
init(input_counter: Int, input_balance: Int){
self.counter = input_counter;
self.balance = input_balance;
}
receive(){
// empty, means do nothing when receive empty body message.
}
}
```
As you can see, we can change the parameters that the second contract need to predetemine the contract address since we got the `stateInit` code.
Does anyone knows how to hardcode an address in smart contract?
Does anyone knows how to hardcode an address in smart contract?
The contract address is a hash of the `**stateInit**` the code.
If you change the initial sotrage of the contract , you are changing the future address of the contract, but contract address is deterministic ( and its knowen before you deploy) you can pass the address to the sotrage , as part of the initializations of the contract.
For example, the Tact language down below shows how I can create a stateInit code to get Smart Contract address:
```
contract Example {
any_int: Int;
init() {
self.any_int = 0;
}
receive("A") {
let contractInit: StateInit = initOf TargetContract(self.any_int, 666);
send(SendParameters{
to: contractAddress(contractInit),
value: 0,
mode: 0 + 64 + 128,
bounce: false
});
}
}
contract TargetContract {
counter: Int;
balance: Int;
init(input_counter: Int, input_balance: Int){
self.counter = input_counter;
self.balance = input_balance;
}
receive(){
// empty, means do nothing when receive empty body message.
}
}
```
As you can see, we can change the parameters that the second contract need to predetemine the contract address since we got the `stateInit` code.
The contract address is a hash of the `**stateInit**` the code.
If you change the initial sotrage of the contract , you are changing the future address of the contract, but contract address is deterministic ( and its knowen before you deploy) you can pass the address to the sotrage , as part of the initializations of the contract.
For example, the Tact language down below shows how I can create a stateInit code to get Smart Contract address:
![123](https://i.postimg.cc/kGLB7txR/Screen-Shot-2023-02-05-at-20-53-11.png)
As you can see, we can change the parameters that the second contract need to predetemine the contract address since we got the `stateInit` code.
Does anyone knows how to hardcode an address in smart contract?
The contract address is a hash of the `**stateInit**` the code.
If you change the initial sotrage of the contract , you are changing the future address of the contract, but contract address is deterministic ( and its knowen before you deploy) you can pass the address to the sotrage , as part of the initializations of the contract.
For example, the Tact language down below shows how I can create a stateInit code to get Smart Contract address:
![123](https://i.postimg.cc/kGLB7txR/Screen-Shot-2023-02-05-at-20-53-11.png)
As you can see, we can change the parameters that the second contract need to predetemine the contract address since we got the `stateInit` code.