title: How to encode call data to a contract
body: <p>Reading through the ink source code (<a href="https://github.com/paritytech/ink/blob/master/core/src/env2/call/utils.rs#L83" rel="nofollow noreferrer">here</a>), my understanding is that a contract call is the selector concatenated with any arguments to the function.</p>
  
  <p>From a Substrate runtime module test, I use the CallData builder which does as described</p>
  
  <pre class="lang-rust prettyprint-override"><code>let mut call = CallData::new( Selector::from_str("foo") );
  call.push_arg(&amp;0);
  </code></pre>
  
  <p>And then make the call through the contracts frame module</p>
  
  <pre class="lang-rust prettyprint-override"><code>let res = &lt;contracts::Module&lt;Test&gt;&gt;::bare_call(      
      ALICE,                                                      
      contract_addr,                                                       
      0,                                                          
      100_000,                                                                                    
      //codec::Encode::encode(&amp;call.to_bytes().to_vec()));        
      call.to_bytes().to_vec());                                  
  
  </code></pre>
  
  <p>To a contract function signature of</p>
  
  <pre><code>fn foo(&amp;self, x: AccountId)
  </code></pre>
  
  <hr>
  
  <p>This returns a successful execution (<code>Ok(())</code>) but does not invoke the contract function.</p>
  
  <p>It's worth saying that the test is using <code>type AccountId = u64</code> and ink uses a <code>struct AccountId([u8;32])</code>, but I've tried passing as 32 bytes and it hasn't made a difference.</p>
  
  <p>I've verified that the surrounding test code should work by calling a wasm program written in wat <a href="https://github.com/jaybutera/nft-registry/blob/master/runtime/src/nftregistry/tests.rs#L265" rel="nofollow noreferrer">here</a>, which is able to call the exported "call" without passing any parameters.</p>
  
  <p>The complete repositories are also on github for the <a href="https://github.com/jaybutera/nft-registry" rel="nofollow noreferrer">module</a> and the <a href="https://github.com/jaybutera/nftregistry-testcontract" rel="nofollow noreferrer">contract</a>.</p>